🔗ally.is.focusRelevant
Determines if an element is considered focusable by script.
🔗Description
Consult the data tables what browsers consider focusable and what ally.js considers focusable to learn how HTML elements behave.
🔗Usage
var element = document.getElementById('victim');
var isFocusRelevant = ally.is.focusRelevant(element);
🔗Arguments
Name | Type | Default | Description |
---|---|---|---|
element | HTMLElement | required | The Element to test. |
🔗Returns
Boolean, true
if the element is focus relevant.
🔗Throws
TypeError
if element
argument is not of type HTMLElement
.
🔗Changes
- Since
v#master
the<embed>
and<keygen>
elements are considered focus-relevant, but not focusable. - Since
v#master
theelement.prototype.matches
polyfill is re-applied to allow elements from other documents (e.g. from an iframe). - Since
v#master
the<object>
element properly distinguishes between SVG and SWF content. - Since
v#master
elements using Flexbox layout are properly identified in IE10 and IE11. - Since
v#master
the Shadow DOM hosts are considered focus-relevant, but not focusable. - Since
v#master
scrollable containers are properly identified in Internet Explorer. - Since
v#master
all<area>
elements are considered focus-relevant.
🔗Notes
NOTE: The
<body>
element may mistakenly considered focusable, because it is the default activeElement if no other element has focus - but it is not focusable, unless made so by adding the tabindex
attribute.NOTE: Because the
<keygen>
element is poorly supported, practically never used and has seen intent to deprecate, ally considers all <keygen>
elements focus-relevant but not focusable.NOTE: Because the behavior of the
<embed>
element depends on the content type and browser plugin, ally considers all <embed>
elements focus-relevant but not focusable.WARNING: Firefox and Internet Explorer cannot focus
SVGElement
s by script, thus no SVG element is considered focusable, see Gecko 1116966WARNING: WebKit and Blink make any
SVGElement
focusable that has a focus
event listener attached, see Blink 445798, WebKit 140024🔗Related resources
ally.is.focusable
tests focus-relevant elements if they're also visible and not disabledally.is.tabbable
tests elements if they're keyboard focusableally.is.validTabindex
is used to verify the element'stabindex
value is validally.query.focusable
finds focusable elements in the DOM