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

fix(dropdown): container body keyboard navigation #3791

Merged

Conversation

benouat
Copy link
Member

@benouat benouat commented Jun 29, 2020

This PR is a follow up PR to #3625 which introduced the ability to close the dropdown when leaving it by the last elements.
Unfortunately, it did not fix the keyboard navigation when using container="body" is used.

Leaving the dropdown menu from the bottom when container is set to "body" leaves the user in a broken state, where the browser window url bar gets the focus.

The PR introduces a mechanism to catch the last Tab from the dropdown menu, and temporary set the focus back in a synchronous fashion to the dropdown anchor, hence letting the browser placing the focus on the next focusable element.

It also makes sure now that whenever the user wants to close the dropdown from the keyboard with Esc, the focus gets back to the dropdown toggle element.

This used to be the broken behaviour that now works
Kapture 2020-06-29 at 11 44 04

Copy link
Member

@maxokorokov maxokorokov left a comment

Choose a reason for hiding this comment

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

Hey, @benouat, LGTM!

Just have:

  • a short question about tabindex
  • a short request to refactor accessing to anchorEl via getNativeElement()

Haven't checked the test coverage on my side.

Cheers,
Max

src/dropdown/dropdown.ts Show resolved Hide resolved
src/dropdown/dropdown.ts Outdated Show resolved Hide resolved
src/dropdown/dropdown.ts Outdated Show resolved Hide resolved
@maxokorokov maxokorokov added this to the 7.0.0 milestone Jul 7, 2020
@benouat benouat force-pushed the fix/dropdown/container-body-tab branch from bc04267 to 6fda4bc Compare July 8, 2020 08:04
@benouat
Copy link
Member Author

benouat commented Jul 8, 2020

I created a new commit regarding the refactoring of how to access nativeElement across both anchor and menu so it could be easier to review.

accross anchor/toggle and menu
@benouat benouat force-pushed the fix/dropdown/container-body-tab branch from 6fda4bc to 567ec09 Compare July 8, 2020 08:16
Copy link
Member

@maxokorokov maxokorokov left a comment

Choose a reason for hiding this comment

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

Hey, @benouat, LGTM!

Just a small detail → I guess the second commit should be refactor, not fix, but I'm not sure if you want to squash them in the end or not.

Cheers,
Max

@benouat
Copy link
Member Author

benouat commented Jul 8, 2020

I guess the second commit should be refactor, not fix, but I'm not sure if you want to squash them in the end or not.

I'll squash it!

@benouat benouat merged commit 6179190 into ng-bootstrap:master Jul 8, 2020
maxokorokov pushed a commit that referenced this pull request Jul 8, 2020
Dropdown keyboard navigation is now fully supporting the "container="body" mode. Navigating a page with dropdowns using `Tab` does not break anymore, and follow the visual order of elements.
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.

None yet

3 participants