🔗ally.is.focusRelevant
Determines if an element has any relevance to focus management.
🔗Description
This module is a pre-filter for ally.is.focusable, ally.is.tabbable, ally.is.onlyTabbable and ally.get.focusRedirectTarget. Elements may be considered focus-relevant, even though they do not in fact be focusable, tabbable, only-tabbable or redirect focus given their current conditions. But any element that is focusable, tabbable, only-tabbable or redirects focus is focus-relevant.
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. |
The underlying rules can also be accessed in the options argument style by calling ally.is.focusRelevant.rules(options):
| Name | Type | Default | Description |
|---|---|---|---|
| context | <selector> | required | The element to examine. The first element of a collection is used. |
| except | <focus identification exception> | {} | 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#masterthe<embed>and<keygen>elements are considered focus-relevant, but not focusable. - Since
v#mastertheelement.prototype.matchespolyfill is re-applied to allow elements from other documents (e.g. from an iframe). - Since
v#masterthe<object>element properly distinguishes between SVG and SWF content. - Since
v#masterelements using Flexbox layout are properly identified in IE10 and IE11. - Since
v#masterthe Shadow DOM hosts are considered focus-relevant, but not focusable. - Since
v#masterscrollable containers are properly identified in Internet Explorer. - Since
v#masterall<area>elements are considered focus-relevant. - Since
v#masterevery element that is either focusable, keyboard focusable, only tabbable or redirects focus is considered focus-relevant. - Since
v#masterexceptions can be passed toally.is.focusRelevant.rules(options). - Since
v#masterIE9 properly resolves SVG links (<a xlink:href="…">).
🔗Notes
<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.<keygen> element is poorly supported, practically never used and has seen intent to deprecate, ally considers all <keygen> elements focus-relevant but not focusable.<embed> element depends on the content type and browser plugin, ally considers all <embed> elements focus-relevant but not focusable.SVGElements by script, thus no SVG element is considered focusable, see Gecko 1116966SVGElement focusable that has a focus event listener attached, see Blink 445798, WebKit 140024🔗Related resources
ally.is.focusabletests focus-relevant elements if they're also visible and not disabledally.is.tabbabletests elements if they're keyboard focusableally.is.validTabindexis used to verify the element'stabindexvalue is validally.query.focusablefinds focusable elements in the DOM