Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const FOCUSABLE_ELEMENTS = `
a[href]:not([tabindex^="-"]):not([inert]),
area[href]:not([tabindex^="-"]):not([inert]),
input:not([disabled]):not([inert]),
select:not([disabled]):not([inert]),
textarea:not([disabled]):not([inert]),
button:not([disabled]):not([inert]),
iframe:not([tabindex^="-"]):not([inert]),
audio:not([tabindex^="-"]):not([inert]),
video:not([tabindex^="-"]):not([inert]),
[contenteditable]:not([tabindex^="-"]):not([inert]),
[tabindex]:not([tabindex^="-"]):not([inert])`;
function getFocusableChildren(node) {
const filter = Array.prototype.filter,
focusableChildren = node.querySelectorAll(FOCUSABLE_ELEMENTS);
return filter.call(focusableChildren, function(child) {
return !!(
child.offsetWidth ||
child.offsetHeight ||
child.getClientRects().length
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment