Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: adding aXe configuration for a11y addon #3285

Merged
merged 4 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions addons/a11y/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ storiesOf('button', module)
));
```

For more customizability. Use the `'configureA11y'` function to configure [aXe options](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axeconfigure).

```js
import React from 'react';
import { storiesOf } from '@storybook/react';

import { checkA11y, configureA11y } from '@storybook/addon-a11y';

const whateverOptionsYouWant = {};
configureA11y(whateverOptionsYouWant);

storiesOf('button', module)
.addDecorator(checkA11y)
.add('Accessible', () => (
<button>
Accessible button
</button>
))
.add('Inaccessible', () => (
<button style={{ backgroundColor: 'red', color: 'darkRed', }}>
Inaccessible button
</button>
));
```

## Roadmap

* Make UI accessibile
Expand Down
4 changes: 2 additions & 2 deletions addons/a11y/src/A11yManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import WrapStory from './components/WrapStory';

// Run all a11y checks inside
class A11yManager {
wrapStory(channel, storyFn, context) {
const props = { context, storyFn, channel };
wrapStory(channel, storyFn, context, axeOptions) {
const props = { context, storyFn, channel, axeOptions };

return <WrapStory {...props} />;
}
Expand Down
6 changes: 5 additions & 1 deletion addons/a11y/src/components/WrapStory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ class WrapStory extends Component {
context: PropTypes.shape({}),
storyFn: PropTypes.func,
channel: PropTypes.shape({}),
axeOptions: PropTypes.shape({}),
};
static defaultProps = {
context: {},
storyFn: () => {},
channel: {},
axeOptions: {},
};

constructor(props) {
Expand All @@ -33,10 +35,12 @@ class WrapStory extends Component {

/* eslint-disable react/no-find-dom-node */
runA11yCheck() {
const { channel } = this.props;
const { channel, axeOptions } = this.props;
const wrapper = findDOMNode(this);

if (wrapper !== null) {
axe.reset();
axe.configure(axeOptions);
axe.a11yCheck(wrapper, {}, results => {
channel.emit('addon:a11y:check', results);
});
Expand Down
9 changes: 7 additions & 2 deletions addons/a11y/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import A11yManager from './A11yManager';
import * as shared from './shared';

const manager = new A11yManager();
let axeOptions = {};

function checkA11y(storyFn, context) {
const channel = addons.getChannel();
return manager.wrapStory(channel, storyFn, context);
return manager.wrapStory(channel, storyFn, context, axeOptions);
}

export { checkA11y, shared };
function configureA11y(options = {}) {
axeOptions = options;
}

export { checkA11y, shared, configureA11y };