fix(core): Combobox, RovingTabIndex and ATFocus controller fixes for rh-select #2963
+43
−2
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.
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.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.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.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>