Giter VIP home page Giter VIP logo

a11ytrap's Introduction

A11yTrap

Trap keyboard navigation within a component. A11yTrap makes it easy to add accessibility support for modals, dropdowns and other web components.

DEMO

Installation

With NPM:

npm install a11ytrap --save

With Bower:

bower install a11ytrap --save

Or include A11yTrap directly:

<script src="/path/to/a11ytrap.js"></script>

Usage

Import A11yTrap and configure a component (all options with default values are shown).

import A11yTrap from 'a11ytrap';

const MyComponent = new A11yTrap('.MyComponent', {
  enableArrowKeys: false,
  focusOnElement: null,
  focusOnFirstElement: false,
  focusOnLastElement: false,
});

MyComponent.init();

A11yTrap will now handle focus management for your component.

By default A11yTrap will include all focusable elements into it's focus management. To add a custom element into the trap add tabindex="0" or a11ytrap-element attribute to your element's markup.

Configuration options

enableArrowKeys

Type: Boolean Default: false

Usage: Allow arrow keys to navigate component.

focusOnElement

Type: Element Default: null

Usage: Begin focus management on a specific focusable element in component.

focusOnFirstElement

Type: Boolean Default: false

Usage: Begin focus management on first focusable element of component.

focusOnLastElement

Type: Boolean Default: false

Usage: Begin focus management on last focusable element of component.

Note: If more than one option is being used A11yTrap will default to focusOnFirstElement.

Methods

init()

Usage: Creates new instance of A11yTrap.

destroy()

Usage: Kills the instance of A11yTrap.

focusElement(index)

Usage: Focus on a element within component.

focusPrevious()

Usage: Focus on previous element.

focusNext()

Usage: Focus on next element.

Todo

  • Add tests
  • Properly handle series of radio inputs
  • Fix issue when destroying and re-enabling A11yTrap
  • Enable arrow key control
  • Enable custom elements

License

MIT License

a11ytrap's People

Contributors

azinasili avatar

Stargazers

 avatar

Watchers

 avatar  avatar

a11ytrap's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.