Skip to content
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

SelectPanel2: Improve keyboard navigation from search input #4199

Merged
merged 4 commits into from
Feb 14, 2024

Conversation

siddharthkp
Copy link
Member

When the focus is on search input,

  1. Pressing ArrowDown should focus the first element in the list
  2. Pressing Tab should should focus the last focused element in the list

When the focus is in the list,

  1. Pressing Up should not come out of the list
  2. Pressing Shift + Tab should move focus to the list
selectpanel-input-keydown.mov

@siddharthkp siddharthkp self-assigned this Jan 30, 2024
@siddharthkp siddharthkp requested a review from a team January 30, 2024 20:07
Copy link

changeset-bot bot commented Jan 30, 2024

🦋 Changeset detected

Latest commit: bcc4bcf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

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

Copy link
Contributor

github-actions bot commented Jan 30, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 113.37 KB (0%)
packages/react/dist/browser.umd.js 114.02 KB (0%)

Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to ask a broader clarification question before reviewing, what kind of role/semantics are we looking for between the input and the listbox? At first glance, this seems like a case where role="combobox" may be appropriate but wanted to check-in to see since the intent here is to shift the focus to the list box.

@siddharthkp
Copy link
Member Author

At first glance, this seems like a case where role="combobox" may be appropriate but wanted to check-in to see since the intent here is to shift the focus to the list box.

Interesting! I can see how that might work. Until now, we've looked at it as a listbox with dynamic content 🤔

cc @ichelsea for clarification though!

selectpanel parts labelled, the list part is labelled as listbox

@ichelsea
Copy link

ichelsea commented Feb 7, 2024

I'm like 90% sure role=combobox can't be used here back when I was working with James, that definitely came up. I can't recall the reason off of the top of my head but I can deep dive into past issues if we need one! (If I recall it partially has to do with multi-select support?)

ARIA in HTML: combobox role. Most comboboxes are associated with a listbox that popups up and is not appearing by default. Also in our case, the list can be accessed independently of the search input where in combobox, the two are inherently connected. The selection of a combobox is typically displayed in the text input as well, which we aren't doing. Multi-select behavior, if it's even supported, isn't expected from assistive technology.

@siddharthkp
Copy link
Member Author

@ichelsea Thank you! That's very helpful

@joshblack Back for your review!

Copy link
Member

@broccolinisoup broccolinisoup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing it on different stories and the focus doesn't move to the list on arrow down when there are sections in the list. Is that intentional or do we want the same focus model when there are sections as well?

select-panel-arrow-down.mp4

A selectpanel pop up is open and displays two sections with headings and options in each. Pressing the arrow down when the focus is on the search input doesn't do anything.

@siddharthkp
Copy link
Member Author

siddharthkp commented Feb 12, 2024

I was testing it on different stories and the focus doesn't move to the list on arrow down when there are sections in the list. Is that intentional or do we want the same focus model when there are sections as well?

That's not intentional at all! You've found a bug with groups :D

Amazing catch, fixed now!

Copy link
Member

@broccolinisoup broccolinisoup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does work now with different variants of the selectbox - thanks for fixing!

Left one comment about adding tests but looks good!

@@ -161,6 +163,14 @@ const Panel: React.FC<SelectPanelProps> = ({
[internalOpen],
)

// used in SelectPanel.SearchInput
const moveFocusToList = () => {
const selector = 'ul[role=listbox] li:not([role=none])'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The selector looks a bit too fragile, makes me a bit nervous 😬 but the query makes a lot of sense. Can we add tests/stories to make sure we always get the intended first element? (It is not a blocker, feel free to merge the PR)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take it up in a new PR!

@siddharthkp siddharthkp added this pull request to the merge queue Feb 14, 2024
Merged via the queue into main with commit b6e5807 Feb 14, 2024
30 checks passed
@siddharthkp siddharthkp deleted the drafts-selectpanel-input-arrowdown branch February 14, 2024 10:19
@github-actions github-actions bot mentioned this pull request Feb 13, 2024
broccolinisoup pushed a commit that referenced this pull request Feb 20, 2024
* add moveFocusToList

* Create fresh-parents-kiss.md

* make selector ignore groups
lukasoppermann pushed a commit that referenced this pull request Apr 16, 2024
* add moveFocusToList

* Create fresh-parents-kiss.md

* make selector ignore groups
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.

4 participants