Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

fix(Modal): add keyboard trap #1115

Merged
merged 9 commits into from
Aug 9, 2018

Conversation

Kyle-Cooley
Copy link
Contributor

Adds a keyboard trap to fix issue #874

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

Hi @Kyle-Cooley thank you for jumping in! One question - Does this fix prevents the “focus-wrap” behavior while the modal is not open?

Adds a keyboard trap to fix issue #874
@Kyle-Cooley
Copy link
Contributor Author

Hello @asudoh. That was a good catch. I have amended my commit to check if the modal is open when trapping focus.

@asudoh
Copy link
Contributor

asudoh commented Jul 24, 2018

Hi @Kyle-Cooley thank you for your quick change! Just a couple of additional things:

  1. Vanilla version moves the focus (back) to modal itself, instead of preventing the focus from moving. Can we align the behaviors?
  2. Vanilla version makes focus to floating menu an exception, due to Overflow menu is not working in a Modal carbon#280. Can we address this in this React variant, too?

FYI here's the corresponding code in vanilla: https://github.com/IBM/carbon-components/blob/3e9bc26/src/components/modal/modal.js#L140-L153

Fixes the modal keyboard trap to be consistent with vanilla behavior.
@Kyle-Cooley
Copy link
Contributor Author

I addressed the first, but I'm struggling with the second. I'm using an overflow menu (floating) in a modal. The items in the menu can be tabbed to, but when the overflow menu closes, focus is not returned to the modal.

Makes it possible to escape keyboard trap in modals when using floating menus
This sends focus back to the overflow menu item after the menu gets closed. This
is important for floating overflow menus in modals.
@Kyle-Cooley
Copy link
Contributor Author

I think I've managed to address the issue, let me know if there is something else.

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

Thanks alot @Kyle-Cooley for your quick change! Looks that we are getting there - Just a couple of comments this time.

this.setState({ open: false }, () => {
if (wasOpen) {
this.focusMenuEl();
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -36,10 +43,21 @@ export default class Modal extends Component {
iconDescription: 'close the modal',
modalHeading: '',
modalLabel: '',
selectorsFloatingMenus: ['.bx--overflow-menu-options__btn'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Made algorithm to check for floating menus check parents as well and
made the list of floating menu selectors consistent with vanilla.
Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

LGTM now 👍 - Thank you very much @Kyle-Cooley for your contribution!

@joshblack
Copy link
Contributor

Hi @Kyle-Cooley! Looks great, mind fixing the merge conflicts and then we can merge?

@Kyle-Cooley
Copy link
Contributor Author

Should be good now.

@joshblack joshblack merged commit 5dc69b9 into carbon-design-system:master Aug 9, 2018
@carbon-bot
Copy link

🎉 This PR is included in version 6.19.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants