@mantine/hooks
Version:
A collection of 50+ hooks for state and UI management
35 lines (31 loc) • 1.16 kB
JavaScript
'use client';
;
var tabbable = require('./tabbable.cjs');
function scopeTab(node, event) {
const tabbable$1 = tabbable.findTabbableDescendants(node);
if (!tabbable$1.length) {
event.preventDefault();
return;
}
const finalTabbable = tabbable$1[event.shiftKey ? 0 : tabbable$1.length - 1];
const root = node.getRootNode();
let leavingFinalTabbable = finalTabbable === root.activeElement || node === root.activeElement;
const activeElement = root.activeElement;
const activeElementIsRadio = activeElement.tagName === "INPUT" && activeElement.getAttribute("type") === "radio";
if (activeElementIsRadio) {
const activeRadioGroup = tabbable$1.filter(
(element) => element.getAttribute("type") === "radio" && element.getAttribute("name") === activeElement.getAttribute("name")
);
leavingFinalTabbable = activeRadioGroup.includes(finalTabbable);
}
if (!leavingFinalTabbable) {
return;
}
event.preventDefault();
const target = tabbable$1[event.shiftKey ? tabbable$1.length - 1 : 0];
if (target) {
target.focus();
}
}
exports.scopeTab = scopeTab;
//# sourceMappingURL=scope-tab.cjs.map