indiana-university / rivet-source

Indiana University’s design system for web application development
https://rivet.iu.edu
BSD 3-Clause "New" or "Revised" License
54 stars 5 forks source link

Dialog fails to trap focus when it contains focusable elements that are temporarily hidden #760

Open levimcg opened 1 week ago

levimcg commented 1 week ago

Describe the bug

If a dialog contains any focusable elements that are temporarily hidden, it still uses the hidden elements when calculating all of the focusable elements inside of itself. This means that in some cases it cannot properly trap focus and a user can use the Tab key to navigate out of the dialog while it is open.

A good example of this would be if a dialog contains a dropdown menu or a disclosure of some sort that has focusable elements inside. If say, the last focusable element is hidden inside a dropdown menu, the dialog doesn't know that it's the last element which means it doesn't know to move focus back to the first focusable element allowing you to navigate out of the focus trap.

Expected behavior

The dialog should only use visible focusable element when determining how to trap focus.

Relevant context (required)

Steps to reproduce

Here is a reduced test case to replicated the bug.

  1. Open the dialog
  2. Use the Tab key to navigate through the dialog
  3. After navigating past the dropdown toggle button, you will move out of the dialog instead of focus being trapped inside.