-
Notifications
You must be signed in to change notification settings - Fork 106
fix(core): improve ATFocus, Combobox, Internals, Listbox, and RovingTabIndex controllers #2963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(core): improve ATFocus, Combobox, Internals, Listbox, and RovingTabIndex controllers #2963
Conversation
🦋 Changeset detectedLatest commit: 4823594 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for patternfly-elements ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
This comment has been minimized.
This comment has been minimized.
|
Regarding |
…ombobox controller" This reverts commit ba6a0dc.
This comment has been minimized.
This comment has been minimized.
bennypowers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a changeset
✅ Commitlint tests passed!More Info{
"valid": true,
"errors": [],
"warnings": [],
"input": "fix(core): improve ATFocus, Combobox, Internals, Listbox, and RovingTabIndex controllers"
} |
…k to EI Attributes are user settings, internals are defaults, so we need to try the attributes first
refactors for readability
|
@adamjohnson @hellogreg I think this is ready to go, please give it the once over |
|
Libraries Grow Tools Maintained |
What I did
Testing Instructions
npm run build.core/pfe-core/controllers/at-focus-controller.js+.d.ts+.js.mapcore/pfe-core/controllers/roving-tabindex-controller.js+.d.ts+.js.mapcore/pfe-core/controllers/combobox-controller.js+.d.ts+.js.mapcore/pfe-core/controllers/listbox-controller.js+.d.ts+.js.mapcore/pfe-core/controllers/internals-controller.js+.d.ts+.js.mapnode_modules/@patternfly/pfe-core/controllersnpm run devin your terminal.Notes to Reviewers
I'll outline what changed and why for each controller:
AT Focus Controller
Prior to these changes, when pressing the Home key for rh-select, focus incorrectly moves to the last item instead of the first. This happens because the
atFocusedItemIndexsetter inATFocusControllercalculates the search direction incorrectly.If the first item is non-focusable (e.g., a disabled placeholder), the while loop searches backward from index 0, wraps to the last item, and stops there.
The solution is to modify the direction calculation in the
atFocusedItemIndexsetter to handle Home/End explicitly. See notes in code for further details.This PR also adds the public
refreshItems()method. This method makes available the option for keyboard users to arrow/focus to items when users dynamically add rh/pf-options after intitial render.Combobox Controller
When using a combobox/select component without a text input (e.g., rh-select), clicking the toggle button while the listbox is open does not close the listbox as expected. Instead, the listbox briefly closes and immediately reopens, preventing the native select-like toggle behavior.
The
#onFocusoutListboxhandler correctly closes the listbox when focus leaves to an external element, but it doesn't account for the case where focus moves to the toggle button itself.The solution is to modify the
#onFocusoutListboxhandler to also check if therelatedTargetis the toggle button. If focus moved to the toggle button, skip the automatic close and let the#onClickButtonhandler manage the toggle behavior.We also implement the new
refreshItems()method insideset items()so that dynamically added rh/pf-options are keyboard accessible after intitial render.Internals Controller
The internals controller includes four new public statics:
setAriaPosInSet,setAriaSetSize,getAriaPosInSet,getAriaSetSizewhich are then used in the Combobox and Listbox controllers to set thosearia-*attributes internally or on the host.RovingTabIndex Controller
The
RovingTabindexControllermaintains an internalatFocusedItemIndexthat tracks which item should have focus. However, this index is only updated via keyboard navigation, not when an item receives DOM focus programmatically or via mouse click. This causes keyboard navigation to start from the wrong position after mouse interactions.Eg: Open the a select and click "Item 3". Item 3 is focused. Re-open the select and hit the down arrow.
Expected: Focus moves to "Item 4". Actual: Focus moves to Item 1.
This change adds a persistent focusin event listener in the RovingTabindexController constructor that syncs atFocusedItemIndex when any item in the container receives DOM focus. This keeps our mouse + keyboard focus in sync.
To Do's
<pf-select>