Fix listbox Home/End/PageUp/PageDown across Select, MultiSelect, and AutocompleteInput (#380) - #436
Merged
Conversation
…put (#380) The listbox key handling lived in two places with different bugs. Pull the decision layer into `internal/listboxKeyboard`, which maps a key event onto an open/move/jump/commit action and leaves `preventDefault()` to the caller. `useListboxNavigation` and `BaseAutocompleteInput` both drive off it now, so Select, MultiSelect, TagsInput, and AutocompleteInput answer to the same keys. That resolves three defects in the listbox map: - Home/End no longer fire while the caret is in a text field, so the search input inside the Select/MultiSelect popover gets them back for caret movement. The target decides, since the same handler is bound to both the search field and the trigger button. - Home/End go to the actual first/last option instead of the selection. `getInitialHighlight` still prefers the selection, but only for opening the listbox with an arrow key -- an explicit jump now uses the new `getEdgeHighlight`. - PageUp/PageDown jump the highlight to the first/last option. They previously fell through to the browser, which page-scrolled the popover away from `aria-activedescendant`. AutocompleteInput picks up the jumps as part of the alignment, plus two smaller consistency fixes it inherits from the shared map: ArrowUp on a closed menu opens it rather than silently moving a hidden highlight, and opening with an arrow key seeds the highlight at the matching edge.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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 #380.
The shared piece
Select/MultiSelect (via
useListboxNavigation) and AutocompleteInput/TagsInput (viaBaseAutocompleteInput) each had their own combobox key handling, with different bugs. This addssrc/internal/listboxKeyboard.ts, a small pure module that maps a key event onto the action a listbox should take:Both handlers now drive off
resolveListboxKeyActionand apply the action to their own state model (value-keyed for the selects, index-keyed for autocomplete).preventDefault()stays with the caller so it can decline an action it can't fulfil — Enter with nothing highlighted still belongs to the form.The three defects
isOpenregardless of target, so the caret couldn't reach the start/end of the query. They now reach the listbox only when the event target has no text caret — the same handler is bound to both the search field and the trigger button, so the target decides.getInitialHighlight, which returns the selected option before honoring the direction. That helper is right for "open the listbox" and wrong for an explicit jump, which now uses a newgetEdgeHighlight.aria-activedescendant. They're now the jump keys that always belong to the listbox, in every combobox.Net keyboard map: arrows own the listbox, Home/End yield to the text caret when there is one, PageUp/PageDown jump to first/last.
AutocompleteInput
Picks up the jumps as part of the alignment, plus two consistency fixes it inherits from the shared map:
-1, so the first arrow press only opened the menu).Tests
Select— Home/End move the search caret and leavearia-activedescendantalone; PageDown jumps to the last filtered option, PageUp back to the first.MultiSelect— with a selection present, ArrowDown opens onto the selection but Home lands on the first option; PageDown/PageUp reach the edges.AutocompleteInput— Home/End keep the caret, PageDown/PageUp jump the highlight, and Enter commits the jumped-to result.Each fails on
main. Full suite: 3177 passing.https://claude.ai/code/session_01XFkkvUQfynGRedEYDNxKoY