A11y config based on global variables? #35279
Replies: 2 comments
|
Hi @hgarfinkle! I'm Dosu and I'm helping the Storybook team. The Here are a couple of approaches you could consider:
Dynamic rule configuration based on globals isn't currently supported. If the separate-stories approach doesn't fit your workflow, this would be a good candidate for a feature request on the repo. Would you like more detail on structuring stories for per-mode a11y testing? To reply, just mention @dosu. Docs are dead. Just use Dosu. |
|
I would treat this as not supported by the addon today, at least for the automatic a11y run. The a11y preview hook gets both const a11yParameter = parameters.a11y
const a11yGlobals = globals.a11y
...
await run(a11yParameter, storyId)
The least hacky setup is to make the modes separate story variants or separate test entries, and put the a11y rule on those static variants: export const Standard = {
globals: { 'contrast-mode': 'standard' },
parameters: {
a11y: {
config: {
rules: [{ id: 'color-contrast', enabled: false }],
},
},
},
}
export const HighContrast = {
globals: { 'contrast-mode': 'high' },
parameters: {
a11y: {
config: {
rules: [{ id: 'color-contrast', enabled: true }],
},
},
},
}That also behaves better in CI, because each story has a deterministic static a11y config. If the goal is an interactive toolbar switch inside one story, you would need a feature change in the addon: something like a function-valued a11y config or passing story globals into the a11y runner before |
Uh oh!
There was an error while loading. Please reload this page.
Summary
I have a Storybook project that offers a "high-contrast mode", which is controlled through an option in
globalTypesin mypreview.tsx. I'm working on setting up accessibility testing for my stories in that project. I only want to report "insufficient contrast" violations when in high-contrast mode, it doesn't bother me if contrast is lower on normal mode. Thus, what I want is to be able to change thea11yconfig in mypreview.tsxto disablecolor-contrastviolations whencontrast-mode === 'standard'. Is this achievable without doing something hacky?Additional information
No response
Create a reproduction
No response
All reactions