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

chore(storybook): Restrict a11y rules on Storybook #1953

Merged
merged 2 commits into from
Oct 11, 2024
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
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.

Loading