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

https://github.com/markcarrrr/react-a11y-accordion

A ReactJS accessible accordion utilising the HTML <details> and <summary> tags for native semantics and accessibility.
https://github.com/markcarrrr/react-a11y-accordion

Last synced: 2 months ago
JSON representation

A ReactJS accessible accordion utilising the HTML <details> and <summary> tags for native semantics and accessibility.

Awesome Lists containing this project

README

          

# react-a11y-accordion ![CI](https://github.com/markcarrrr/react-a11y-accordion/workflows/CI/badge.svg)

A ReactJS accessible accordion utilising the HTML `` and `` tags for native semantics and accessibility.

> Browser support - Can I use HTML5 ``: https://caniuse.com/#feat=details

> Supports React 16.0.0 or newer.

## Installing

```
yarn add @markcarrrr/react-a11y-accordion
```

OR

```
npm install --save @markcarrrr/react-a11y-accordion
```

## Example Usage

```js
import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (


Accordion content 1.


Accordion content 2.


);
```

## Props

### Required

`header`

- type: `string`
- default: `"react-a11y-accordion"`

Pass in text for the accordion header (output within the `` tag).

```js
import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (


Accordion content 1.


Accordion content 2.


);
```

### Optional

`onlyOneOpen`

- type: `boolean`
- default: `false`

Allow only one accordion item to be open at any time. Please note if for any reason multiple `open` props are added to the `` child components then only the first item with an `open` prop will be open.

```js
import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (


Accordion content 1.


Accordion content 2.


);
```

`onSelect`

- type: `(isOpen: boolean, currentId: string): void;`
- default: `undefined`

Callback on accordion item selection. Returns open state and id for selected item.

```js
import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (
{})}>

Accordion content 1.


Accordion content 2.


);
```

`id`

- type: `string`
- default: auto-generated

Pass in an id for the accordion item wrapper (applied on the `` tag).

```js
import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (


Accordion content 1.


Accordion content 2.


);
```

`open`

- type: `boolean`
- default: `false`

Add if you want the item open by default (applied on the `` tag). Please note if `onlyOneOpen` has been added to `` and for any reason multiple `open` props are added to the `` child components then only the first item with an `open` prop will be open.

```js
import { Accordion, AccordionItem } from '@markcarrrr/react-a11y-accordion';

export default () => (


Accordion content 1.


Accordion content 2.


);
```

## Styling

There is purposfully no styling added allowing you to style as required from a clean state.

The BEM methodology has been used for classnames.

```html



...
...



```

## Development

### Initial steps

1. `git clone https://github.com/markcarrrr/react-a11y-accordion.git`
1. `yarn install`

### Scripts

#### Build code

`yarn build`

#### Start local dev server

`yarn start`

#### Lint code

`yarn lint`

#### Format code

`yarn format`

#### Run tests

`yarn test`

## Authors

- **Mark Carr** - _Initial work_ - [markcarrrr](https://github.com/markcarrrr)

## License

This project is licensed under the ISC License - see the [LICENSE.md](LICENSE.md) file for details