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

Focus trap for MdModal component #40

Merged
merged 2 commits into from
Dec 5, 2023
Merged

Conversation

kajsaeggum
Copy link
Contributor

Describe your changes

When a modal is displayed, with a backdrop, it is not possible via mouse to interact with any other parts of the UI. The user is effectively trapped within the modal and has to close the modal before being able to click links, buttons, etc. on the page below.

The same should be true when using keyboard for navigation: when the modal is displayed it should not be possible to use the tab-key to get to other UI elements below the modal. Before this change, that was possible to do.

I've added a focus trap, that will make sure that when the last focusable element in the modal is reached, the next tab-keypress takes you back to the first focusable element in the modal. So it's not possible to get to the other UI elements of the page below without first closing the modal properly.

Checklist before requesting a review

  • I have performed a self-review and test of my code
  • If new component: Is story for component created in stories-folder?
  • If new component: Is tsx-file import added to packages/react/index.tsx?
  • If new component: Is css-file added to packages/css/index.css?

@kajsaeggum kajsaeggum requested a review from a team as a code owner December 5, 2023 13:35
Copy link
Contributor

@aurorascharff aurorascharff left a comment

Choose a reason for hiding this comment

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

Fantastisk, dette problemet dukket opp for meg forrige uke :)

@kajsaeggum kajsaeggum merged commit 9cd6a5a into main Dec 5, 2023
@kajsaeggum kajsaeggum deleted the feature/focusTrapOnModal branch December 5, 2023 14:15
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.

2 participants