Skip to content

Commit

Permalink
chore(storybook): Restrict a11y rules on Storybook (#1953)
Browse files Browse the repository at this point in the history
<!-- Is your PR related to an issue? Then please link it via the
"Relates to #" below. Else, remove it. -->

Relates to #641 

Restrict a11y rules on Storybook
  • Loading branch information
MajaZarkova authored Oct 11, 2024
1 parent 4128866 commit be794c6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/sit-onyx/.storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ import { onyxThemeGlobalType, withOnyxTheme } from "./theme-switch";
import "@fontsource-variable/source-code-pro";
import "@fontsource-variable/source-sans-3";
import "@sit-onyx/storybook-utils/style.css";
import { getRules, Spec } from "axe-core";
import { a11yTags } from "../src/a11yConfig";
import "../src/styles/index.scss";
import "./docs-template.scss";
import { enhanceFormInjectedSymbol } from "./formInjected";
import { enhanceManagedSymbol } from "./managed";
import { withOnyxVModelDecorator } from "./vModel";

const enabledRules = getRules(a11yTags).map((ruleMetadata) => ({
id: ruleMetadata.ruleId,
enabled: true,
}));

const axeConfig: Spec = { rules: enabledRules };

const basePreview = createPreview({
argTypesEnhancers: [enhanceManagedSymbol, enhanceFormInjectedSymbol],
parameters: {
Expand All @@ -24,6 +33,9 @@ const basePreview = createPreview({
headingSelector: ".sb-anchor > h3, #properties-events-and-slots, #examples",
},
},
a11y: {
config: axeConfig,
},
},
globalTypes: {
...onyxThemeGlobalType,
Expand Down
1 change: 1 addition & 0 deletions packages/sit-onyx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@sit-onyx/shared": "workspace:^",
"@storybook/addon-a11y": "^8.3.5",
"@vue/compiler-dom": "catalog:",
"axe-core": "^4.10.0",
"eslint-plugin-vue-scoped-css": "^2.8.1",
"sass-embedded": "catalog:",
"vue": "catalog:",
Expand Down
1 change: 1 addition & 0 deletions packages/sit-onyx/src/a11yConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a11yTags = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"];
3 changes: 2 additions & 1 deletion packages/sit-onyx/src/playwright/a11y.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AxeBuilder from "@axe-core/playwright";
import { test as base } from "@playwright/experimental-ct-vue";
import { a11yTags } from "../a11yConfig";

export { expect } from "@playwright/experimental-ct-vue";

Expand All @@ -17,7 +18,7 @@ type AxeFixture = {
export const test: ReturnType<typeof base.extend<AxeFixture>> = base.extend<AxeFixture>({
makeAxeBuilder: async ({ page }, use) => {
const makeAxeBuilder = () => {
return new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"]);
return new AxeBuilder({ page }).withTags(a11yTags);
};

await use(makeAxeBuilder);
Expand Down
2 changes: 1 addition & 1 deletion packages/sit-onyx/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"playwright.config.*",
"package.json",
".storybook/*.ts",
"src/index.ts"
"src/a11yConfig.ts"
],
"compilerOptions": {
"composite": true,
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be794c6

Please sign in to comment.