Skip to content

Instantly share code, notes, and snippets.

@giuseppeg
Created March 10, 2020 22:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuseppeg/304e6676e6d766b7ebc7f76b84a6e749 to your computer and use it in GitHub Desktop.
Save giuseppeg/304e6676e6d766b7ebc7f76b84a6e749 to your computer and use it in GitHub Desktop.
const focusableSelectors = [
'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])'
].join(',')
function isFocusable(node) {
if (node.nodeType !== 1) { return false }
return (
node.matches(focusableSelectors) &&
// is visible
Boolean(
node.offsetWidth ||
node.offsetHeight ||
node.getClientRects().length
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment