An open API service indexing awesome lists of open source software.

https://github.com/19h47/19h47-accordion

🪗
https://github.com/19h47/19h47-accordion

accordion javascript panel

Last synced: 6 months ago
JSON representation

🪗

Awesome Lists containing this project

README

        

# @19h47/accordion

> Sur un petit air d'accordéon Léon

## Installation

```
yarn add @19h47/accordion
```

## Usage

```javascript
import Accordion from '@19h47/accordion';

const $element = document.querySelector('.js-accordion');
const accordion = new Accordion($element);
accordion.init();
```

```html




Toggle



Sit amet, consectetur adipisicing elit. Omnis ex inventore tempore. Quam voluptas
quibusdam excepturi accusantium voluptatum facere. Nemo vero iste recusandae, at
magnam tenetur maxime ad optio veniam!

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque, molestias
excepturi molestiae nesciunt alias. Nobis aut praesentium, commodi minus laborum
ullam at quod soluta qui tempore sit eveniet dicta esse.




```

## Keyboard Support

| Key | Function |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| _Space_ or _Enter_ | When focus is on the accordion header of a collapsed section, expands the section. |
| _Tab_ |


  • Moves focus to the next focusable element.

  • All focusable elements in the accordion are included in the page `Tab` sequence.

|
| _Shift + Tab_ |

  • Moves focus to the previous focusable element.

  • All focusable elements in the accordion are included in the page `Tab` sequence.

|
| _Down Arrow_ |

  • When focus is on an accordion header, moves focus to the next accordion header.

  • When focus is on last accordion header, moves focus to first accordion header.

|
| _Up Arrow_ |

  • When focus is on an accordion header, moves focus to the previous accordion header.

  • When focus is on first accordion header, moves focus to last accordion header.

|
| _Home_ | When focus is on an accordion header, moves focus to the first accordion header. |
| _End_ | When focus is on an accordion header, moves focus to the last accordion header. |

## Role, Property, State, and Tabindex Attributes

| Role | Attribute | Element | Usage |
| ------ | ------------------ | ------- | ------------------------------------------------------------------------------- |
| | aria-controls="ID" | button | oints to the ID of the panel which the header controls. |
| region | | div | Creates a landmark region that contains the currently expanded accordion panel. |

## Option

Options can be set as `data-attribute`.

### Open

Is the panel open or not.

```html
Button
```

### Deselect

Can the panel be deselected or not.

```html
Button
```

## Event

### Open

```javascript
import Accordion from '@19h47/accordion';

const $element = document.querySelector('.js-accordion');
const accordion = new Accordion($element);

accordion.init();

accordion.panels.forEach(panel => {
panel.el.addEventListener('Panel.open', ({ detail }) => {
console.log({ detail });
});
});
```

### Close

```javascript
import Accordion from '@19h47/accordion';

const $element = document.querySelector('.js-accordion');
const accordion = new Accordion($element);

accordion.init();

accordion.panels.forEach(panel => {
panel.el.addEventListener('Panel.close', ({ detail }) => {
console.log({ detail });
});
});
```

## Build Setup

```bash

# install dependencies
$ yarn install

# serve with hot reload at localhost:3000
$ yarn serve

# build for production
$ yarn build

```

## Example

An example is located right [here](https://19h47.github.io/19h47-accordion/), see [sources](/docs/index.html).

## Acknowledgments

- [Accessible toggle tabs and accordion](https://gomakethings.com/accessible-toggle-tabs-and-accordions/)
- [Accordion](https://www.w3.org/TR/wai-aria-practices-1.1/examples/accordion/accordion.html)