A11yOffCanvas
A fully accessible and customizable off-canvas front-end component. Use your own markup and styles and let A11yOffCanvas do the hard stuff for you.
Installation
A11yOffCanvas is available at:
Source | |
---|---|
NPM | npm install a11yoffcanvas --save |
Yarn | yarn add a11yoffcanvas |
unpkg | https://unpkg.com/a11yoffcanvas |
Usage
A11yOffCanvas does require minimal amount of markup to function:
<!-- - Trigger for drawer must have `data-a11yoffcanvas-trigger` attribute must point to the id of it's corresponding drawer-->Open drawer<!-- - Although the drawer is not required to be an `<aside>`, semantically it's an appropriate tag to use - Drawers must have an unique id - Drawers must have `data-a11yoffcanvas-drawer` attribute--> <!-- - Add optional `data-a11yoffcanvas-close` attribute to be able to close drawers --> x
// Import A11yOffCanvas if utilizing JS modules; // Create a new instance of A11yOffCanvas// All options and default values shownconst drawerTrigger = document;const offcanvas = drawerTrigger drawerCloseClass: null drawerOpenClass: null closeOnClick: false afterCloseFunction: null afterOpenFunction: null beforeCloseFunction: null beforeOpenFunction: null addEvents: false trapFocus: true; // Initialize your new tabsoffcanvas;
A11yOffCanvas will handle all ARIA roles/attributes, focus management, and events, which transform the original HTML into the following:
Open drawer x
A11yOffCanvas API
Options
Property | Type | Default | Description |
---|---|---|---|
drawerCloseClass | String | null |
Class to add to drawer when closed |
drawerOpenClass | String | null |
Class to add to drawer when opened |
closeOnClick | String | null |
Close drawer when clicking outside outside of it |
afterCloseFunction | Function | null |
Function to run after drawer closes |
afterOpenFunction | Function | null |
Function to run after drawer opens |
beforeCloseFunction | Function | null |
Function to run before drawer closes |
beforeOpenFunction | Function | null |
Function to run before drawer opens |
addEvents | Boolean | false |
Add custom A11yOffCanvas events |
trapFocus | Boolean | true |
Trap focus within opened drawer |
Methods
Name | Description |
---|---|
init | Initializes instance of A11yOffCanvas |
destroy | Kills instance of A11yOffCanvas |
open | Open drawer |
close | Close drawer |
License
MIT License