Skip to content

Instantly share code, notes, and snippets.

@dmstern
Last active March 11, 2020 04:48
Show Gist options
  • Save dmstern/fecb87174993db010257c55241ce5834 to your computer and use it in GitHub Desktop.
Save dmstern/fecb87174993db010257c55241ce5834 to your computer and use it in GitHub Desktop.
function isVisible(element) {
const style = window.getComputedStyle(element);
return style.display !== 'none';
}
function isFocusable (element) {
const focusableElements = [
'a[href]',
'button:enabled',
'input:enabled',
'select:enabled',
'textarea:enabled',
'option:enabled',
'[tabindex]:not([tabindex="-1"])'
];
const focusable = focusableElements.join(', ');
return isVisible(element) && element.matches(focusable);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment