storybook/addons/a11y/README.md

87 lines
2.3 KiB
Markdown
Raw Normal View History

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)
2019-06-03 11:06:42 -07:00
![Screenshot](https://raw.githubusercontent.com/storybookjs/storybook/HEAD/addons/a11y/docs/screenshot.png)
2016-10-02 18:20:27 +02:00
## Getting started
First, install the addon.
```sh
$ yarn add @storybook/addon-a11y --dev
2016-10-02 18:20:27 +02: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
module.exports = {
2020-02-25 10:34:19 -05:00
addons: ['@storybook/addon-a11y'],
};
2016-10-02 18:20:27 +02:00
```
```js
import React from 'react';
export default {
title: 'button',
};
export const accessible = () => <button>Accessible button</button>;
export const inaccessible = () => (
<button style={{ backgroundColor: 'red', color: 'darkRed' }}>Inaccessible button</button>
);
2016-10-02 18:20:27 +02: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:
```js
2020-02-25 10:34:19 -05:00
export const MyNonCheckedStory = () => <SomeComponent />;
MyNonCheckedStory.parameters = {
a11y: { disable: true },
};
```
## Parameters
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';
import { storiesOf, addDecorator, addParameters } from '@storybook/react';
2018-03-26 01:25:33 -07: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: {},
// optional flag to prevent the automatic check
2019-11-19 10:10:10 +01:00
manual: true,
},
},
};
export const accessible = () => <button>Accessible button</button>;
export const inaccessible = () => (
<button style={{ backgroundColor: 'red', color: 'darkRed' }}>Inaccessible button</button>
);
2018-03-26 01:25:33 -07:00
```
## Roadmap
- Make UI accessible
- Show in story where violations are.
- Add more example tests
- Add tests
- Make CI integration possible