a11y-tools
v1.0.1
Published
Simple accessibility helpers
Downloads
6
Maintainers
Readme
A11y Tools
Collection of simple accessibility helpers.
Installation
npm install a11y-tools
ARIA
Hide/Show
import { ariaHide, ariaShow } from 'a11y-tools'
ariaHide(element) // set aria-hidden="true"
ariaShow(element) // set aria-hidden="false"
Disable/Enable
import { ariaDisable, ariaEnable } from 'a11y-tools'
ariaDisable(element) // set aria-disabled="true"
ariaEnable(element) // set aria-disabled="false"
Input States
import { ariaCheck, ariaUncheck, ariaSelect, ariaUnselect, ariaPress, ariaUnpress } from 'a11y-tools'
ariaCheck(element) // set aria-checked="true"
ariaUncheck(element) // set aria-checked="false"
ariaSelect(element) // set aria-selected="true"
ariaUnselect(element) // set aria-selected="false"
ariaPress(element) // set aria-pressed="true"
ariaUnpress(element) // set aria-pressed="false"
Current
import { ariaCurrent } from 'a11y-tools'
ariaCurrent(element) // set aria-current="true"
ariaCurrent(element, false) // set aria-current="false"
ariaCurrent(element, 'page') // set aria-current="page"
ariaCurrent(element, null) // remove aria-current
Expand/Contract
element
= Toggle element (button)
label
= Text content of toggle element
container
= Content container (DOM element)
import { ariaExpand, ariaContract } from 'a11y-tools'
ariaExpand(element) // set aria-expanded="true"
ariaContract(element) // set aria-expanded="false"
ariaExpand(element, { container, label = 'Close' })
ariaContract(element, { container, label = 'Open' })
Focus
Trap focus
import { trapFocus } from 'a11y-tools'
// Trap focus inside element
const focusTrapUndoFunction = trapFocus(element, {
unfocusElements: true // aria-hide sibling containers?
})
// Restore focus to previously focused element
focusTrapUndoFunction()
Focus element
import { focus } from 'a11y-tools'
// Focus first tabbable child element without scrolling to it
focus(element, { scroll: false })
Speech
Announce to screenreaders
import { speak } from 'a11y-tools'
speak('Navigated to page: About')