2016-10-02 18:20:27 +02:00
# storybook-addon-a11y
2018-11-19 20:43:40 -06:00
This storybook addon can be helpful to make your UI components more accessible.
2016-10-02 18:20:27 +02:00
2019-06-03 11:06:42 -07:00
[Framework Support ](https://github.com/storybookjs/storybook/blob/master/ADDONS_SUPPORT.md )
2018-02-21 15:41:32 +02:00
2019-06-03 11:06:42 -07:00

2016-10-02 18:20:27 +02:00
## Getting started
First, install the addon.
2017-11-11 22:08:01 +01:00
```sh
2018-12-10 19:27:12 +01:00
$ yarn add @storybook/addon -a11y --dev
2016-10-02 18:20:27 +02:00
```
2019-11-25 21:02:23 +01:00
Add this line to your `main.js` file (create this file inside your storybook config directory if needed).
2016-10-02 18:20:27 +02:00
```js
2019-11-25 21:02:23 +01:00
module.exports = {
2020-02-25 10:34:19 -05:00
addons: ['@storybook/addon -a11y'],
2020-01-31 12:35:25 -07:00
};
2016-10-02 18:20:27 +02:00
```
```js
import React from 'react';
2019-11-25 21:02:23 +01:00
export default {
title: 'button',
};
2020-01-31 12:35:25 -07:00
export const accessible = () => < button > Accessible button< / button > ;
2019-11-25 21:02:23 +01:00
export const inaccessible = () => (
2020-01-31 12:35:25 -07:00
< button style = {{ backgroundColor: ' red ' , color: ' darkRed ' } } > Inaccessible button< / button >
2019-11-25 21:02:23 +01:00
);
2016-10-02 18:20:27 +02:00
```
2017-11-11 22:08:01 +01:00
2020-02-25 10:34:19 -05:00
If you wish to selectively disable `a11y` checks for a subset of stories, you can control this with story parameters:
2020-01-31 12:35:25 -07:00
```js
2020-02-25 10:34:19 -05:00
export const MyNonCheckedStory = () => < SomeComponent / > ;
2020-05-25 15:24:48 +08:00
MyNonCheckedStory.parameters = {
a11y: { disable: true },
2020-01-31 12:35:25 -07:00
};
```
2019-11-24 12:58:15 +01:00
## Parameters
2019-11-25 21:02:23 +01:00
For more customizability use parameters to configure [aXe options ](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axeconfigure ).
2020-10-14 13:11:00 +05:30
You can override these options [at story level too ](https://storybook.js.org/docs/react/configure/features-and-behavior#per-story-options ).
2018-03-26 01:25:33 -07:00
```js
import React from 'react';
2018-12-10 19:27:12 +01:00
import { storiesOf, addDecorator, addParameters } from '@storybook/react ';
2018-03-26 01:25:33 -07:00
2019-11-25 21:02:23 +01:00
export default {
title: 'button',
parameters: {
a11y: {
// optional selector which element to inspect
element: '#root ',
// axe-core configurationOptions (https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#parameters -1)
config: {},
// axe-core optionsParameter (https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options -parameter)
options: {},
2020-01-31 12:35:25 -07:00
// optional flag to prevent the automatic check
2019-11-19 10:10:10 +01:00
manual: true,
2019-11-25 21:02:23 +01:00
},
2019-01-04 20:22:31 +01:00
},
2019-11-25 21:02:23 +01:00
};
2020-01-31 12:35:25 -07:00
export const accessible = () => < button > Accessible button< / button > ;
2019-11-25 21:02:23 +01:00
export const inaccessible = () => (
2020-01-31 12:35:25 -07:00
< button style = {{ backgroundColor: ' red ' , color: ' darkRed ' } } > Inaccessible button< / button >
2019-11-25 21:02:23 +01:00
);
2018-03-26 01:25:33 -07:00
```
2017-11-11 22:08:01 +01:00
## Roadmap
2020-01-31 12:35:25 -07:00
- Make UI accessible
- Show in story where violations are.
- Add more example tests
- Add tests
- Make CI integration possible