Created
March 10, 2020 22:19
-
-
Save giuseppeg/304e6676e6d766b7ebc7f76b84a6e749 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 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