fix(react-aria): make aria-posinset global across sections in listbox and menu - #10487
Open
gonzoblasco wants to merge 2 commits into
Open
fix(react-aria): make aria-posinset global across sections in listbox and menu#10487gonzoblasco wants to merge 2 commits into
gonzoblasco wants to merge 2 commits into
Conversation
… and menu aria-posinset was computed from item.index, which restarts at 0 within each section, while aria-setsize uses getItemCount (the global item count). This made the two attributes inconsistent for sectioned collections (e.g. Picker with sections), where the first option reported posinset=2 with setsize=6. Compute the position as a global item count that ignores section headers, consistent with aria-setsize. Applies to useOption and useMenuItem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9556
Summary
aria-posinseton virtualized listbox/menu options was computed fromitem.index, which restarts at0within each section.aria-setsize, however, usesgetItemCount- the global item count that ignores section headers. For sectioned collections this made the two attributes inconsistent: e.g. on the Picker sections example, the first option reportedaria-posinset=2whilearia-setsize=6, and numbering restarted per group.Changes
Added a shared
getPosInSethelper (packages/react-aria/src/utils/posinset.ts) that computes the option's 1-based position as a global item count, ignoring section headers, so it stays consistent witharia-setsize. Items not inside a section keep their existing O(1) index-based position (no behavior change there).Applied it to both hooks that had the same pattern:
useOption(ListBox / Picker / Select / ComboBox options)useMenuItem(menus)Test
Added a unit test covering a virtualized menu with two sections:
aria-posinsetis now1..4across sections (not restarting per group) and matchesaria-setsize=4.Behavior
posinset=2(section header counted), restarting per section against a globalsetsize.posinsetis global (1..N), consistent witharia-setsize.