Skip to content

Fix: Trap focus in overlaid popups (Issue #3141)#3206

Closed
Capezzuto wants to merge 2 commits into
EFForg:masterfrom
Capezzuto:fix/trap-focus-in-nag
Closed

Fix: Trap focus in overlaid popups (Issue #3141)#3206
Capezzuto wants to merge 2 commits into
EFForg:masterfrom
Capezzuto:fix/trap-focus-in-nag

Conversation

@Capezzuto

Copy link
Copy Markdown

This code update should address issue #3141 (Keyboard navigation not properly trapped within welcome page reminder/critical error/important update notification modal). Changes are scoped to elements in "#instruction" dialog element in popup.html.

@ghostwords

This comment was marked as outdated.

@lenacohen lenacohen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for opening this PR! I tested each of the nag modals and focus trapping works!

However, the trap works now because #instruction comes before all other focusable elements in the DOM. Focus isn't explicitly moved into the modal when it opens. If a focusable element is ever added earlier in popup.html, the first Tab press will focus there instead of inside the modal, and focus won't be trapped in the modal until the user tabs into it.

Comment thread src/js/popup.js
Comment on lines +94 to +97
let is_tab = e.key === "Tab" || e.keycode === 9;
if (!is_tab) {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

keycode will be undefined because the property is keyCode, but I think you can remove the check because the property is deprecated (https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) and key is supported by Privacy Badger's minimum browser versions

@ghostwords

Copy link
Copy Markdown
Member

Thank you for contributing to Privacy Badger!

If we take a step back, what we're dealing with here is a partially-implemented dialog element. This pull request is a step towards a more complete implementation, one that correctly handles keyboard navigation.

As far as I can see though, there is no need at this point to re-implement dialog. I think we should switch our implementation to dialog, which will automatically take care of keyboard trapping, as well as of other things that we may or may not be doing properly in our custom implementation.

Would you be interested in opening a new pull request that fixes #3141 by switching #instruction from div to dialog?

@Capezzuto

Copy link
Copy Markdown
Author

Sure, I work on that approach. With that being the case, please feel free to close this PR.

@ghostwords ghostwords added the a11y Accessibility label Jul 17, 2026
@ghostwords ghostwords closed this Jul 20, 2026
@ghostwords

Copy link
Copy Markdown
Member

Let me know if I can help with the dialog pull request! Feel free to open a work-in-progress version that we can complete together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a11y Accessibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants