Skip to content

Add shift-tab keyboard support for dialogs (modal & Offcanvas components)#33865

Merged
XhmikosR merged 7 commits into
twbs:mainfrom
RyanBerliner:dialog-focus
Jul 27, 2021
Merged

Add shift-tab keyboard support for dialogs (modal & Offcanvas components)#33865
XhmikosR merged 7 commits into
twbs:mainfrom
RyanBerliner:dialog-focus

Conversation

@RyanBerliner
Copy link
Copy Markdown
Contributor

@RyanBerliner RyanBerliner commented May 7, 2021

Fixes #28481

  • Share focus trapping behavior between modal and Offcanvas components
  • Allow shift-tab keyboard navigation to wrap around backwards (go to the last focusable element)

There are a couple issues (primarily #33804) that aim to fix inconsistent screen reader navigation or announcements. The work I've done here only concerns tab navigation.

TODO:

Preview Modal
Preview Offcanvas

Comment thread js/src/dom/selector-engine.js Outdated
Comment thread js/src/offcanvas.js Outdated
Comment thread js/src/util/focustrap.js Outdated
Comment thread js/src/util/focustrap.js Outdated
Comment thread js/src/offcanvas.js Outdated
@RyanBerliner RyanBerliner force-pushed the dialog-focus branch 2 times, most recently from b6b8f06 to 7e7a0a5 Compare May 21, 2021 00:50
@RyanBerliner RyanBerliner marked this pull request as ready for review May 21, 2021 00:56
@RyanBerliner RyanBerliner requested a review from a team as a code owner May 21, 2021 00:56
@GeoSot
Copy link
Copy Markdown
Member

GeoSot commented Jun 6, 2021

@RyanBerliner can you rebase your MR please?

@RyanBerliner
Copy link
Copy Markdown
Contributor Author

@GeoSot I've rebased. It looks like #33327 introduced a dependency of selector-engine.js for util/index.js. Combine this with my previous work on this PR and it's throwing circular dependency warning between the util index and selector engine files. I'm open to any number of resolutions, though IMO it seems that the getElement() in the util index file might be best suited living in the selector engine file? Let me know what you'd prefer to see done.

@GeoSot
Copy link
Copy Markdown
Member

GeoSot commented Jun 8, 2021

though IMO it seems that the getElement() in the util index file might be best suited living in the selector engine file?

Yes, seems right as it has a foreign dependency. Can you handle it ? (maybe isElement need to follow getElement)
I suppose is better on a separate MR

/cc @rohit2sharma95 , @alpadev

@RyanBerliner
Copy link
Copy Markdown
Contributor Author

I hadn't realized how dependent other utility functions were on getElement() and isElement()... so moving either of those to selector engine would likely turn into some larger, and questionable refactoring. To avoid this I've decided instead to move focusableChildren() to the utility file. I think this can be justified since focusableChildren() does have some more opinionated logic in it that isn't as straight forward as the other selector engine functions.

@GeoSot GeoSot self-assigned this Jun 10, 2021
Comment thread js/src/util/focustrap.js Outdated
@GeoSot
Copy link
Copy Markdown
Member

GeoSot commented Jul 6, 2021

Seems good to my eyes.

CC: @twbs/js-review

@GeoSot GeoSot requested a review from a team July 6, 2021 22:49
GeoSot
GeoSot previously approved these changes Jul 6, 2021
@GeoSot GeoSot requested review from a team and GeoSot July 8, 2021 14:04
@GeoSot GeoSot dismissed their stale review July 14, 2021 09:30

changes cuased of #34441

@GeoSot
Copy link
Copy Markdown
Member

GeoSot commented Jul 20, 2021

@RyanBerliner , can we update this MR (and resolve the suggestion)?

@XhmikosR
Copy link
Copy Markdown
Member

@patrickhlauke: LGTY?

@XhmikosR XhmikosR requested a review from patrickhlauke July 21, 2021 16:05
@XhmikosR
Copy link
Copy Markdown
Member

FYI This doesn't pass on BrowserStack + there are some warnings: https://github.com/twbs/bootstrap/runs/3125887723

We should get those sorted before landing this :)

@RyanBerliner
Copy link
Copy Markdown
Contributor Author

@XhmikosR the warnings seem simple enough, I can handle them. The failed tests on the other hand seem to be related to differences in how the <area> tag is selected. This came up in #33960, and we decided to just drop special handling of this element... I'm wondering if you all think it may be most practical to drop it from the selector here as well since it's used so little. Otherwise, happy to troubleshoot... just want to make sure everyone believes it's worth it since it's a funky element. I'm leaning towards dropping it.

@GeoSot
Copy link
Copy Markdown
Member

GeoSot commented Jul 26, 2021

I will support the 'drop' case, for one more time. However try to leave a comment about it, for future reference

Copy link
Copy Markdown
Member

@patrickhlauke patrickhlauke left a comment

Choose a reason for hiding this comment

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

Testing the behaviour, this now seems to behave correctly. Not looked at the code side, but from a functional point of view, this looks good to me

@RyanBerliner
Copy link
Copy Markdown
Contributor Author

@XhmikosR I'm not sure I have the permission to re-run browserstack tests, however I believe everything should be resolved. If there are still warnings or errors that you'd like me to revisit lmk.

@XhmikosR
Copy link
Copy Markdown
Member

All good @RyanBerliner thanks!

Also, thanks to @GeoSot everything seems to be good to go.

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.

v5: Modal focus changes

5 participants