Skip to content

Commit

Permalink
partially apply configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldpipowitch committed Nov 11, 2019
1 parent 85a8acc commit c74b1f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion addons/a11y/README.md
Expand Up @@ -56,7 +56,6 @@ import { withA11y } from '@storybook/addon-a11y';
addDecorator(withA11y)
addParameters({
a11y: {
// ... axe options
element: '#root', // optional selector which element to inspect
config: {}, // axe-core configurationOptions (https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#parameters-1)
options: {} // axe-core optionsParameter (https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter)
Expand Down
14 changes: 8 additions & 6 deletions addons/a11y/src/index.ts
Expand Up @@ -48,18 +48,20 @@ if (module && module.hot && module.hot.decline) {
module.hot.decline();
}

let storedSetup: Setup | null = null;
let storedDefaultSetup: Setup | null = null;

export const withA11y = makeDecorator({
name: 'withA11Y',
parameterName: PARAM_KEY,
wrapper: (getStory, context, { parameters }) => {
if (parameters) {
storedSetup = setup;
setup = parameters as Setup;
} else if (storedSetup) {
setup = storedSetup;
storedSetup = null;
if (storedDefaultSetup === null) {
storedDefaultSetup = { ...setup };
}
Object.assign(setup, parameters as Setup);
} else if (storedDefaultSetup !== null) {
Object.assign(setup, storedDefaultSetup);
storedDefaultSetup = null;
}
addons.getChannel().on(EVENTS.REQUEST, () => run(setup.element, setup.config, setup.options));

Expand Down

0 comments on commit c74b1f6

Please sign in to comment.