-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[@mantine/hooks] use-focus-trap: shift + tab bug #4679
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,19 @@ export function scopeTab(node: HTMLElement, event: KeyboardEvent) { | |
} | ||
const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1]; | ||
const root = node.getRootNode() as unknown as DocumentOrShadowRoot; | ||
const leavingFinalTabbable = finalTabbable === root.activeElement || node === root.activeElement; | ||
let leavingFinalTabbable = finalTabbable === root.activeElement || node === root.activeElement; | ||
|
||
// Handle the case of the active element being in a RadioGroup with the finalTabbable element | ||
if (root.activeElement instanceof HTMLInputElement && root.activeElement.type === 'radio') { | ||
const activeRadioGroup = tabbable.filter( | ||
(element) => | ||
element instanceof HTMLInputElement && | ||
root.activeElement instanceof HTMLInputElement && | ||
element.type === 'radio' && | ||
element.name === root.activeElement.name | ||
); | ||
leavingFinalTabbable = activeRadioGroup.includes(finalTabbable); | ||
} | ||
Comment on lines
+14
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This, obviously, is only a solution for Radio Groups, but I suspect there's similar behavior for other elements. Another idea I had was to get the next target, and check if it's in |
||
|
||
if (!leavingFinalTabbable) { | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't appear to be working as expected, though it does pass when I run as part of a different codebase. We use the following versions of testing library. Was there a breaking change?