Repository navigation
feat: support ArrowUp and ArrowDown on single-select dropdowns - #1357
Open
sviat-barbutsa wants to merge 1 commit into
Open
sviat-barbutsa wants to merge 1 commit into
sviat-barbutsa wants to merge 1 commit into
Conversation
Comment on lines
-65
to
-67
| bubbles: true, | ||
| cancelable: false, | ||
| composed: true, |
| await user.keyboard('{ArrowDown}{ArrowUp}') | ||
|
|
||
| expect(element).toHaveFocus() | ||
| expect(getEventSnapshot()).toMatchInlineSnapshot(` |
Contributor
There was a problem hiding this comment.
it doesn't look like this is the order of events in the browser
https://jsfiddle.net/0ukrw85p/
Contributor
There was a problem hiding this comment.
Please make sure to read all the comments in the original issue you linked to, I believe it pointed this out.
| }, | ||
| ) | ||
|
|
||
| test('read available options after keydown listeners run', async () => { |
| }, | ||
| ) | ||
|
|
||
| test.each([['Alt'], ['Control'], ['Shift'], ['Meta']])( |
Contributor
There was a problem hiding this comment.
This doesn't appear to match the browser. Control+ArrowUp/Down does something special on Mac, but all the other combinations appear to open the select. At least in Chrome.
This branch has not been deployed
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.
What
Refs #786. With a native single-select focused,
await user.keyboard('{ArrowDown}')now selects the next available option.ArrowUpmoves back. Both keys keep focus on the dropdown. A change firesinputand thenchangebeforekeyup. At either end of the list, or when an app cancelskeydown, the selection stays put.Why
The New York Public Library linked #786 when adding interaction tests for its design system. The team could test choosing a color with the mouse, but the keyboard events it tried never changed the selection. Its current story uses
selectOptionsto choose Green and Black. NYPL’s PR · Current Select storyI tried the same color list locally with NYPL’s published React component (4.6.0). Starting on Red, I pressed Down three times and Up once. Native Chrome selected Green, Blue, Black, then Blue. On current
main,user.keyboardstayed on Red through all four presses. With this patch, it matched Chrome on every press, and the form submitted Blue.How
The keydown handler reads the current options after application listeners run. It skips disabled options, disabled groups and options hidden with
display: none, then updates the selected option using the same event dispatch asselectOptions. This covers plain Up and Down on a collapsed dropdown. Opening a native popup with Space and committing a highlighted choice with Enter is a separate part of #786.I added 15 cases. Six fail on unmodified
main. All 594 Jest tests pass on Linux and Windows. The 15 new cases also pass in each of the three toolbox environments. Across the full toolbox run, I got the same 19 failures on cleanmainand the patch. Type-checking, lint and the Linux build passed. The Windows build stopped on the same ESM path error on both revisions.I also compared 51 key presses per browser on Windows. Chrome, Edge and Opera matched on every press. Firefox differed on Up from an empty selection, and Playwright WebKit also differed on which hidden options it visits. The patch follows Chromium for those cases. I could test WebKit on Windows only.
Checklist