We should explore implementing a focus trap pattern in the Overlay component for accessibility purposes.
Desired Behavior
- When the image browser overlay UI is visible, focus should be automatically moved to the "close" button in the top right corner
- if the user navigates to other focus-able elements via the Tab key or similar, they should never be able to focus on parts of the page that are hidden by the overlay. Instead, if they reach the end of the interactive elements within the overlay, pressing Tab again should take them back to the first focusable element (the close button most likely).
- Shift+Tab should also behave in the same way, in the reverse direction
- Any focusable elements in sub-components (like Visual Table of Contents links) should be reachable this way
- The behavior of the Esc key (which closes the modal overlay) should not be impacted in any way
Prior implementations to reference
The Codex Dialog component implements a focus trap that behaves in this manner. I think that we could port over the code from the Codex Dialog into our own Overlay component without too much modification.
QA Steps
- Log into Patchdemo instance (link) – test on article pages with images
- Open the Overlay UI by clicking on any image in the carousel
- Confirm that keyboard navigation (tab, shift + tab works correctly and that focus can never move to elements outside of the overlay. Focus should loop back around at the end (and going in reverse from the start should loop back to the last focusable element within the overlay).
- Comment with any issues discovered, otherwise this task can be moved to sign-off column.




