Skip to content

Commit

Permalink
Radio ScopeTab (shift+tab) _ts_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Shresth72 committed Sep 24, 2023
1 parent f01899d commit a7a36e0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/mantine-hooks/src/use-focus-trap/scope-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ 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
const activeElement = root.activeElement as Element;
const activeElementIsRadio =
activeElement.tagName === 'INPUT' && activeElement.getAttribute('type') === 'radio';
if (activeElementIsRadio) {
const activeRadioGroup = tabbable.filter(
(element) =>
element.getAttribute('type') === 'radio' &&
element.getAttribute('name') === activeElement.getAttribute('name')
);
leavingFinalTabbable = activeRadioGroup.includes(finalTabbable);
}

if (!leavingFinalTabbable) {
return;
Expand Down

0 comments on commit a7a36e0

Please sign in to comment.