Class A11yHelper
Constructors
constructor
- new
A11y (): A11yHelperHelper Returns A11yHelper
Accessors
Static
debug
- get debug(): boolean
Returns boolean
Global debugging enabled.
- set debug(debug): void
Parameters
- debug: boolean
Global debug enabled
Returns void
- debug: boolean
Static
prefersReducedMotion
- get prefersReducedMotion(): boolean
Runs a media query to determine if the user / OS configuration is set up for reduced motion / animation.
Returns boolean
User prefers reduced motion.
Methods
Static
applyFocusSource
- apply
Focus (options): voidSource Apply focus to the HTMLElement / SVGElement targets in a given A11yFocusSource data object. An iterable list
options.focusEl
can contain HTMLElement / SVGElements or selector strings. If multiple focus targets are provided in a list then the first valid target found will be focused. If focus target is a string then a lookup viadocument.querySelector
is performed. In this case you should provide a unique selector for the desired focus target.Note: The body of this method is postponed to the next clock tick to allow any changes in the DOM to occur that might alter focus targets before applying.
Parameters
- options: A11yFocusSource | {
focusSource: A11yFocusSource;
}The focus options instance to apply.
Returns void
- options: A11yFocusSource | {
Static
getFirstFocusableElement
- get
First (element?, options?): FocusableElementFocusable Element Returns first focusable element within a specified element.
Parameters
Returns FocusableElement
First focusable child element.
Static
getFocusableElements
- get
Focusable (element?, options?): FocusableElement[]Elements Returns all focusable elements within a specified element.
Parameters
Optional
element: Element | DocumentOptional element to start query.
Optional
options: {
anchorHref?: boolean;
ignoreClasses?: Iterable<string, any, any>;
ignoreElements?: Set<Element>;
selectors?: string;
}Optional parameters.
Optional
anchorHref ?: booleanWhen true anchors must have an HREF.
Optional
ignoreClasses ?: Iterable<string, any, any>Iterable list of classes to ignore elements.
Optional
ignoreElements ?: Set<Element>Set of elements to ignore.
Optional
selectors?: stringCustom list of focusable selectors for
querySelectorAll
.
Returns FocusableElement[]
Child keyboard focusable elements.
Static
getFocusSource
- get
Focus (options): A11yFocusSourceSource Gets a A11yFocusSource object from the given DOM event allowing for optional X / Y screen space overrides. Browsers (Firefox / Chrome) forwards a mouse event for the context menu keyboard button. Provides detection of when the context menu event is from the keyboard. Firefox as of (1/23) does not provide the correct screen space coordinates, so for keyboard context menu presses coordinates are generated from the centroid point of the element.
A default fallback element or selector string may be provided to provide the focus target. If the event comes from the keyboard however the source focused element is inserted as the target with the fallback value appended to the list of focus targets. When A11yFocusSource is applied by A11yHelper.applyFocusSource the target focus list is iterated through until a connected target is found and focus applied.
Parameters
- options: {
debug?: boolean;
event?: MouseEvent | KeyboardEvent;
focusEl?: string | FocusableElement;
x?: number;
y?: number;
}Options
Optional
debug?: booleanWhen true A11yHelper.applyFocusSource logs focus target data.
Optional
event?: MouseEvent | KeyboardEventThe source DOM event.
Optional
focusEl ?: string | FocusableElementA specific HTMLElement / SVGElement or selector string as the focus target.
Optional
x?: numberUsed when an event isn't provided; integer of event source in screen space.
Optional
y?: numberUsed when an event isn't provided; integer of event source in screen space.
Returns A11yFocusSource
A A11yFocusSource object.
See
- https://bugzilla.mozilla.org/show_bug.cgi?id=1426671
- https://bugzilla.mozilla.org/show_bug.cgi?id=314314
TODO: Evaluate / test against touch input devices.
- options: {
Static
getLastFocusableElement
- get
Last (element?, options?): FocusableElementFocusable Element Returns first focusable element within a specified element.
Parameters
Returns FocusableElement
Last focusable child element.
Static
isFocusable
Static
isFocusSource
- is
Focus (data): booleanSource Convenience method to check if the given data is a valid focus source.
Parameters
- data: string | Element
Either an HTMLElement, SVGElement, or selector string.
Returns boolean
Is valid focus source.
- data: string | Element
Static
isFocusTarget
- is
Focus (element): booleanTarget Tests if the given
element
is a Element node and has afocus
method.Parameters
- element: Element
Element to test for focus method.
Returns boolean
Whether the element has a focus method.
- element: Element
Provides several helpful utility methods for accessibility and keyboard navigation.
Note: Global debugging can be enabled by setting
A11yHelper.debug = true
.