Skip to content

fix(react-aria): make aria-posinset global across sections in listbox and menu - #10487

Open
gonzoblasco wants to merge 2 commits into
adobe:mainfrom
gonzoblasco:fix/aria-posinset-sections
Open

fix(react-aria): make aria-posinset global across sections in listbox and menu#10487
gonzoblasco wants to merge 2 commits into
adobe:mainfrom
gonzoblasco:fix/aria-posinset-sections

Conversation

@gonzoblasco

Copy link
Copy Markdown

Fixes #9556

Summary

aria-posinset on virtualized listbox/menu options was computed from item.index, which restarts at 0 within each section. aria-setsize, however, uses getItemCount - 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 reported aria-posinset=2 while aria-setsize=6, and numbering restarted per group.

Changes

Added a shared getPosInSet helper (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 with aria-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-posinset is now 1..4 across sections (not restarting per group) and matches aria-setsize=4.

Behavior

  • Before: first option in a sectioned collection reported posinset=2 (section header counted), restarting per section against a global setsize.
  • After: posinset is global (1..N), consistent with aria-setsize.

… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect aria-posinset for Pickers with Sections

1 participant