0.0.1 • Published 6 years ago

aria-autopilot v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Aria Autopilot, Declarative accessibility

License: MIT npm version Donate with PayPal

Aria Autopilot binds interactive behavior based on declarative rules.

It exposes a set of instructions often used when building interactive widgets.

Aria Autopilot is currently a work in progress

We can bind ARIA attributes using data-aria-autopilot attribute, Aria Autopilot will then automatically apply the attributes when loaded. Aria Autopilot uses MutationObserver to automatically expand attributes defined on dynamically inserted DOM elements.

Time to learn ES6?

Aria Autopilot is written in ES6.

If you want to learn how to write modern ES6 JavaScript as well, I highly recommend ES6 for Everyone by Wes Bos.

Installation

It's best if Aria Autopilot runs as quickly as possible after loading the DOM. If you put the script reference in the <head> and add a defer attribute to it the browser will load the script in parralel with your HTML and will automatically execute it once the DOM is ready.

<!doctype html>
<html>
  <head>
    <title>Aria Autopilot</title>
    <script defer src="aria-autopilot.min.js"></script>
  </head>
  <body>

  </body>
</html>

Configuration

Instruction format

An @event happens, a relation is found, a sequence of actions is run.

@event: relation -> action
@event: relation -> action, action
@event: relation(parameter, paremeter, ...) -> action; relation -> action, action

Available events

EventDescription
activateTriggered on click or return key pressed
expandTriggered when the aria-expanded attribute is switched to "true"
collapseTriggered when the aria-expanded attribute is switched to "false"
pressTriggered when the aria-pressed attribute is switched to "true"
releaseTriggered when the aria-pressed attribute is switched to "false"
selectTriggered when the aria-selected attribute is switched to "true"
deselectTriggered when the aria-selected attribute is switched to "false"
targetTriggered when the element is the target of the location hash
key_upTriggered on key up pressed
key_downTriggered on key down pressed
key_leftTriggered on key left pressed
key_rightTriggered on key right pressed
key_escapeTriggered on escape key pressed
key_enterTriggered on enter key pressed
key_spaceTriggered on spacebar pressed
key_tabTriggered on tab key pressed
key_backspaceTriggered on backspace pressed
key_codeTriggered on key press with given code

Available relations

RelationDescription
origin(childSelector)the first element referencing this element
target(childSelector)the element targetted by this element via href, aria-controls or if both are missing the next sibling
context(childSelector)the current element
siblings(childSelector, parentSelector)the siblings of this element
next-sibling(childSelector, parentSelector)the next sibling of this element
previous-sibling(childSelector, parentSelector)the previous sibling of this element
last-sibling(childSelector, parentSelector)the last sibling of this element
first-sibling(childSelector, parentSelector)the first sibling of this element

Available actions

ActionDescription
selectSets the aria-selected attribute to "true" and fires the select event
deselectSets the aria-selected attribute to "false" and fires the deselect event
pressSets the aria-pressed attribute to "true" and fires the press event
releaseSets the aria-pressed attribute to "false" and fires the release event
expandSets the aria-expanded attribute to "true" and fires the expand event
collapseSets the aria-expanded attribute to "false" and fires the collapse event
toggleToggles the aria state on the element and fires the related event
activateSets the aria state on the element to "true" and fires the related event
deactivateSets the aria state on the element to "false" and fires the related event
focusMoves focus to the selected element
showSets the hidden attribute to "false" on the element
hideSets the hidden attribute to "true" on the element
show-targetshow the target element (the element reference by href, aria-controls or the next sibling)
hide-targethide the target element (the element reference by href, aria-controls or the next sibling)
set-focusableSets the tabindex of the element to "0" allowing user focus
set-script-focusableSets the tabindex of the element to "-1" allowing script focus
update-locationUpdate window location hash with element id

Versioning

Versioning follows Semver.

License

MIT