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

Shift+Tab Model with ShadowRoot #2777

Open
thomson02 opened this issue Nov 7, 2023 · 0 comments · May be fixed by #2778
Open

Shift+Tab Model with ShadowRoot #2777

thomson02 opened this issue Nov 7, 2023 · 0 comments · May be fixed by #2778

Comments

@thomson02
Copy link

thomson02 commented Nov 7, 2023

  • components: Modal.js
  • reactstrap version master. (discovered in 8.4.1)
  • react version #16
  • bootstrap version #4.4

What is happening?

In my application I noticed strange behaviour when shift+tab within a modal dialog window. When using shift+tab instead of going to the previous input I would be taken to the last input in the modal dialog and would be stuck there.

I discovered this is because my modal dialog is rendered within a ShadowRoot and the "getFocusedChild" function within Modal.js does not consider this use case.

What should be happening?

Shift+Tab within a modal dialog should cycle through all the input elements.

Code

`
getFocusedChild() {
let currentFocus;
const focusableChildren = this.getFocusableChildren();

try {
  currentFocus = document.activeElement;
} catch (err) {
  currentFocus = focusableChildren[0];
}
return currentFocus;

}
`

Issue is the use of "document.activeElement". When a modal is displayed within a ShadowRoot then document.activeElement is the shadowRoot container rather than the active element within the shadow root. To fix this a recursive function such as the one found on this site https://www.abeautifulsite.net/posts/finding-the-active-element-in-a-shadow-root/ is required.

@thomson02 thomson02 linked a pull request Nov 7, 2023 that will close this issue
8 tasks
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 a pull request may close this issue.

1 participant