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

Automatically select an item in the dropdown when using arrow keys #34052

Merged
merged 3 commits into from
May 22, 2021

Conversation

alpadev
Copy link
Contributor

@alpadev alpadev commented May 21, 2021

@alpadev alpadev requested a review from a team as a code owner May 21, 2021 02:30
@alpadev
Copy link
Contributor Author

alpadev commented May 21, 2021

@patrickhlauke addressed the key up/down behaviour you mentioned 👍

@XhmikosR
Copy link
Member

So, this looks good, just one observation. The v4 branch just opens the dropdown on the first arrow down/up and only goes to one direction.

@alpadev
Copy link
Contributor Author

alpadev commented May 21, 2021

So, this looks good, just one observation. The v4 branch just opens the dropdown on the first arrow down/up and only goes to one direction.

v4 branch? 😯 I didn't backport it yet, or did I?

@XhmikosR
Copy link
Member

I know, just mentioning the differences in the behavior. :)

@alpadev
Copy link
Contributor Author

alpadev commented May 21, 2021

Oh ok.. 😅 I got a bit confused for sec. If you want me to change it for v4 too, I can do that.

@alpadev alpadev marked this pull request as draft May 21, 2021 14:13
@alpadev alpadev force-pushed the alpa/dropdown-arrow-keys-a11y branch from 1cff37d to 4734a68 Compare May 21, 2021 14:54
@alpadev alpadev closed this May 21, 2021
@alpadev alpadev deleted the alpa/dropdown-arrow-keys-a11y branch May 21, 2021 14:55
@alpadev alpadev restored the alpa/dropdown-arrow-keys-a11y branch May 21, 2021 14:57
@alpadev alpadev reopened this May 21, 2021
@alpadev
Copy link
Contributor Author

alpadev commented May 21, 2021

Dang, I tried to rename the branch but I had no idea that the PR will be closed too 😫

alpadev added 2 commits May 21, 2021 17:02
feat: automatically select an item in the dropdown when using arrow keys

test: add test for getNextActiveElement

to allow the behaviour of returning the last item in case the active element is absent and we want the previous item and cycling is allowed

feat: allow getNextActiveElement to return the last item if the active element is absent

refactor: simplify the ARROW_UP_KEY implementation
@alpadev alpadev force-pushed the alpa/dropdown-arrow-keys-a11y branch from 4734a68 to 52dbaf2 Compare May 21, 2021 15:03
@alpadev alpadev marked this pull request as ready for review May 21, 2021 15:03
Comment on lines +267 to +269
// if the element does not exist in the list return an element depending on the direction and if cycle is allowed
if (index === -1) {
return list[0]
return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked with @GeoSot about adding the feature of getting the last item from getNextActiveElement() in case the item is not in the list, we want the previous item and cycling is allowed. (To reflect the case when the dropdown button is the target of the event and the ARROW_UP_KEY is pressed.) He was ok with adding it.

But I'd appreciate to receive some other opinion.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@XhmikosR XhmikosR merged commit b39b665 into main May 22, 2021
@XhmikosR XhmikosR deleted the alpa/dropdown-arrow-keys-a11y branch May 22, 2021 07:58
@XhmikosR
Copy link
Member

@alpadev can you backport this please?

@XhmikosR
Copy link
Member

@alpadev @rohit2sharma95 friendly ping about the backport :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dropdown keyboard fixes
3 participants