# a11yoffcanvas

> A fully accessible and customizable off-canvas front-end component.

Latest version **3.0.2** (published 2018-11-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install a11yoffcanvas
pnpm add a11yoffcanvas
yarn add a11yoffcanvas
bun add a11yoffcanvas
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2018-11-09 |
| First published | 2017-04-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Azin Asili |
| Maintainers | azinasili |
| Keywords | a11yoffcanvas, a11y, accessible, accessiblity, component, front-end, tabs, customizable |

## Links

- npm: https://www.npmjs.com/package/a11yoffcanvas
- Repository: https://github.com/azinasili/a11yoffcanvas
- Issues: https://github.com/azinasili/a11yoffcanvas/issues
- npm.io page: https://npm.io/package/a11yoffcanvas

## Dependencies (1)

- [a11ytrap](https://npm.io/package/a11ytrap.md) ^1.0.2

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2018-11-09
- 3.0.1 — 2018-11-09
- 3.0.0 — 2018-11-05
- 1.1.0 — 2017-05-13
- 1.0.3 — 2017-05-13
- 1.0.2 — 2017-05-09
- 1.0.1 — 2017-05-09
- 1.0.0 — 2017-04-18
- 0.0.1 — 2017-04-06

## README

# 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.

[DEMO](https://codepen.io/azinasili/pen/adNZxo?editors=0010)

## Installation

A11yOffCanvas is available at:

| Source |  |
|:-------|:-|
| NPM    | `npm install a11yoffcanvas --save` |
| Yarn   | `yarn add a11yoffcanvas` |
| unpkg  | [`https://unpkg.com/a11yoffcanvas`](https://unpkg.com/a11yoffcanvas) |

## Usage

A11yOffCanvas does require minimal amount of markup to function:

```html
<!--
  - Trigger for drawer must have `data-a11yoffcanvas-trigger` attribute must point to the id of it's corresponding drawer
-->
<button data-a11yoffcanvas-trigger="drawerLeft">Open drawer</button>
<!--
  - 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
-->
<aside id="drawerLeft" data-a11yoffcanvas-drawer>
  <!--
    - Add optional `data-a11yoffcanvas-close` attribute to be able to close drawers
  -->
  <a href="#" data-a11yoffcanvas-close>x</a>
</aside>
```

```javascript
// Import A11yOffCanvas if utilizing JS modules
import A11yOffCanvas from 'a11yoffcanvas';

// Create a new instance of A11yOffCanvas
// All options and default values shown
const drawerTrigger = document.querySelector('button');
const offcanvas = new A11yOffCanvas(drawerTrigger, {
  drawerCloseClass: null,
  drawerOpenClass: null,
  closeOnClick: false,
  afterCloseFunction: null,
  afterOpenFunction: null,
  beforeCloseFunction: null,
  beforeOpenFunction: null,
  addEvents: false,
  trapFocus: true,
});

// Initialize your new tabs
offcanvas.init();
```

A11yOffCanvas will handle all ARIA roles/attributes, focus management, and events, which transform the original HTML into the following:

```html
<button data-a11yoffcanvas-toggle="drawerLeft" aria-controls="drawerLeft" aria-expanded="false">Open drawer</button>
<aside id="drawerLeft" data-a11yoffcanvas-drawer aria-hidden="true">
  <a href="#" data-a11yoffcanvas-close>x</a>
</aside>
```

## 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

---
_Source: https://npm.io/package/a11yoffcanvas · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
