Last active
February 17, 2022 21:25
-
-
Save mxmason/c4fadc3bd55571bce511b497a36eb788 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FOCUSABLE_ELEMENTS = ` | |
[contenteditable]:not([tabindex^="-"]):not([inert]):not([aria-hidden="true"]), | |
[tabindex]:not([tabindex^="-"]):not([inert]):not([aria-hidden="true"]) | |
a[href]:not([tabindex^="-"]):not([inert]):not([aria-hidden="true"]), | |
area[href]:not([tabindex^="-"]):not([inert]):not([aria-hidden="true"]), | |
audio:not([tabindex^="-"]):not([inert]):not([aria-hidden="true"]), | |
button:not([disabled]):not([inert]):not([aria-hidden="true"]), | |
iframe:not([tabindex^="-"]):not([inert]):not([aria-hidden="true"]), | |
input:not([disabled]):not([inert]):not([aria-hidden="true"]), | |
select:not([disabled]):not([inert]):not([aria-hidden="true"]), | |
textarea:not([disabled]):not([inert]):not([aria-hidden="true"]), | |
video:not([tabindex^="-"]):not([inert]):not([aria-hidden="true"])`; | |
function _isNodeHidden(node) { | |
if (node.getClientRects().length === 0) { | |
return true; | |
} else { | |
return window.getComputedStyle(node).visibility === "hidden"; | |
} | |
} | |
function getFocusableChildren(node) { | |
const elems = node.querySelectorAll(FOCUSABLE_ELEMENTS); | |
const focusableChildren = []; | |
const len = elems.length; | |
let elem; | |
let i; | |
for (i = 0; i < len; i++) { | |
elem = elems[i]; | |
if (!_isNodeHidden(el)) { | |
focusableChildren.push(el); | |
} | |
} | |
return focusableChildren; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment