From 4ad0d795a6d4e0b437cdeb5f04080090968f4eff Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 5 Sep 2022 15:30:49 +0200 Subject: [PATCH 1/9] move all a11y stories to be renderer agnostic into addons/a11y/template/stories --- .../template/stories/parameters.stories.ts | 63 +++++++++++++++++++ .../html-kitchen-sink/.storybook/preview.js | 7 --- code/examples/official-storybook/preview.js | 7 --- .../stories/addon-a11y/base-button.stories.js | 30 --------- .../stories/addon-a11y/button.stories.js | 19 ------ .../stories/addon-a11y/form.stories.js | 33 ---------- .../stories/addon-a11y/highlight.stories.js | 56 ----------------- .../stories/addon-a11y/image.stories.js | 33 ---------- .../stories/addon-a11y/parameters.stories.js | 38 ----------- .../stories/addon-a11y/typography.stories.js | 48 -------------- .../server-kitchen-sink/.storybook/preview.js | 7 --- .../.storybook/preview.js | 7 --- 12 files changed, 63 insertions(+), 285 deletions(-) create mode 100644 code/addons/a11y/template/stories/parameters.stories.ts delete mode 100644 code/examples/official-storybook/stories/addon-a11y/base-button.stories.js delete mode 100644 code/examples/official-storybook/stories/addon-a11y/button.stories.js delete mode 100644 code/examples/official-storybook/stories/addon-a11y/form.stories.js delete mode 100644 code/examples/official-storybook/stories/addon-a11y/highlight.stories.js delete mode 100644 code/examples/official-storybook/stories/addon-a11y/image.stories.js delete mode 100644 code/examples/official-storybook/stories/addon-a11y/parameters.stories.js delete mode 100644 code/examples/official-storybook/stories/addon-a11y/typography.stories.js diff --git a/code/addons/a11y/template/stories/parameters.stories.ts b/code/addons/a11y/template/stories/parameters.stories.ts new file mode 100644 index 000000000000..acdf0d143c2c --- /dev/null +++ b/code/addons/a11y/template/stories/parameters.stories.ts @@ -0,0 +1,63 @@ +import globalThis from 'global'; + +export default { + component: globalThis.Components.Button, + args: { + children: 'Click Me!', + }, + parameters: { + chromatic: { disable: true }, + }, +}; + +export const Basic = {}; + +export const Violation = { + args: { + // empty on purpose to get a button with no text + children: '', + }, +}; + +export const Checks = { + parameters: { + a11y: { + config: {}, + options: { + checks: { + 'color-contrast': { options: { noScroll: true } }, + }, + restoreScroll: true, + }, + }, + }, +}; + +export const Targetted = { + parameters: { + a11y: { + element: 'button', + }, + }, +}; + +export const Blank = { + parameters: { + a11y: { + config: { + disableOtherRules: true, + // @ts-ignore + rules: [], + }, + options: {}, + }, + }, +}; + +export const Disabled = { + parameters: { + a11y: { + disable: true, + }, + }, +}; diff --git a/code/examples/html-kitchen-sink/.storybook/preview.js b/code/examples/html-kitchen-sink/.storybook/preview.js index 8bf7046aef32..9952d3d77794 100644 --- a/code/examples/html-kitchen-sink/.storybook/preview.js +++ b/code/examples/html-kitchen-sink/.storybook/preview.js @@ -1,11 +1,4 @@ export const parameters = { - a11y: { - config: {}, - options: { - checks: { 'color-contrast': { options: { noScroll: true } } }, - restoreScroll: true, - }, - }, docs: { iframeHeight: '200px', }, diff --git a/code/examples/official-storybook/preview.js b/code/examples/official-storybook/preview.js index e4e0ef7fa7d9..d9a9ffa5ed45 100644 --- a/code/examples/official-storybook/preview.js +++ b/code/examples/official-storybook/preview.js @@ -173,13 +173,6 @@ export const decorators = [ export const parameters = { exportedParameter: 'exportedParameter', - a11y: { - config: {}, - options: { - checks: { 'color-contrast': { options: { noScroll: true } } }, - restoreScroll: true, - }, - }, actions: { argTypesRegex: '^on.*' }, options: { storySort: (a, b) => diff --git a/code/examples/official-storybook/stories/addon-a11y/base-button.stories.js b/code/examples/official-storybook/stories/addon-a11y/base-button.stories.js deleted file mode 100644 index 94d91b5b9ed5..000000000000 --- a/code/examples/official-storybook/stories/addon-a11y/base-button.stories.js +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react'; -import BaseButton from '../../components/BaseButton'; -import DelayedRender from '../../components/DelayedRender'; - -const text = 'Testing the a11y addon'; - -export default { - title: 'Addons/A11y/BaseButton', - component: BaseButton, - parameters: { - options: { selectedPanel: 'storybook/a11y/panel' }, - }, -}; - -export const Default = () => ; -export const Label = () => ; -export const Disabled = () => ; - -export const InvalidContrast = () => ( - // FIXME: has no effect on score - -); -InvalidContrast.storyName = 'Invalid contrast'; - -export const DelayedRenderStory = () => ( - - - -); -DelayedRenderStory.storyName = 'delayed render'; diff --git a/code/examples/official-storybook/stories/addon-a11y/button.stories.js b/code/examples/official-storybook/stories/addon-a11y/button.stories.js deleted file mode 100644 index ba4521b71929..000000000000 --- a/code/examples/official-storybook/stories/addon-a11y/button.stories.js +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; -import Button from '../../components/addon-a11y/Button'; - -const text = 'Testing the a11y addon'; - -export default { - title: 'Addons/A11y/Button', - component: Button, - parameters: { - options: { selectedPanel: 'storybook/a11y/panel' }, - }, -}; - -export const Default = () => + +
+

low contrast

+ +
+
+

missing label

+ +
+
+

missing alt

+ +
+ `, + }, +}; + +export const Passes = { + args: { + content: ` +
+

heading

+

heading 1

+
+
+

button

+ +
+
+

contrast

+ +
+
+

label

+ +
+
+

alt

+ placeholder +
+ `, + }, +}; From d1cff3af861ae0a1e3a2326461bd5ed44eb3e484 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 7 Sep 2022 12:14:27 +0200 Subject: [PATCH 5/9] cleanup --- .../ember-cli/stories/addon-a11y.stories.js | 17 -------- .../addon-a11y.stories.storyshot | 27 ------------ .../stories/addon-a11y.stories.js | 27 ------------ .../stories/addons/a11y.stories.json | 42 ------------------- .../stories/addons/a11y/addon-a11y.stories.ts | 26 ------------ 5 files changed, 139 deletions(-) delete mode 100644 code/examples/ember-cli/stories/addon-a11y.stories.js delete mode 100644 code/examples/html-kitchen-sink/stories/__snapshots__/addon-a11y.stories.storyshot delete mode 100644 code/examples/html-kitchen-sink/stories/addon-a11y.stories.js delete mode 100644 code/examples/server-kitchen-sink/stories/addons/a11y.stories.json delete mode 100644 code/examples/web-components-kitchen-sink/src/stories/addons/a11y/addon-a11y.stories.ts diff --git a/code/examples/ember-cli/stories/addon-a11y.stories.js b/code/examples/ember-cli/stories/addon-a11y.stories.js deleted file mode 100644 index 92cb2a614cfd..000000000000 --- a/code/examples/ember-cli/stories/addon-a11y.stories.js +++ /dev/null @@ -1,17 +0,0 @@ -import { hbs } from 'ember-cli-htmlbars'; - -export default { - title: 'Addon/a11y', - parameters: { - options: { selectedPanel: '@storybook/a11y/panel' }, - }, -}; - -export const Default = () => hbs``; -export const Label = () => hbs``; -export const Disabled = () => hbs``; - -export const InvalidContrast = () => - hbs``; - -InvalidContrast.storyName = 'Invalid contrast'; diff --git a/code/examples/html-kitchen-sink/stories/__snapshots__/addon-a11y.stories.storyshot b/code/examples/html-kitchen-sink/stories/__snapshots__/addon-a11y.stories.storyshot deleted file mode 100644 index d2f9a117a089..000000000000 --- a/code/examples/html-kitchen-sink/stories/__snapshots__/addon-a11y.stories.storyshot +++ /dev/null @@ -1,27 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Storyshots Addons/a11y Default 1`] = ` -`; - -exports[`Storyshots Addons/a11y Invalid contrast 1`] = ` - -`; - -exports[`Storyshots Addons/a11y Label 1`] = ` - -`; diff --git a/code/examples/html-kitchen-sink/stories/addon-a11y.stories.js b/code/examples/html-kitchen-sink/stories/addon-a11y.stories.js deleted file mode 100644 index f9ce4af87a50..000000000000 --- a/code/examples/html-kitchen-sink/stories/addon-a11y.stories.js +++ /dev/null @@ -1,27 +0,0 @@ -import global from 'global'; - -const { document, setTimeout } = global; -const text = 'Testing the a11y addon'; - -export default { - title: 'Addons/a11y', - parameters: { - options: { selectedPanel: 'storybook/a11y/panel' }, - }, -}; - -export const Default = () => ``; -export const Label = () => ``; -export const Disabled = () => ``; -export const Story4 = () => - ``; -Story4.storyName = 'Invalid contrast'; - -export const Story5 = () => { - const div = document.createElement('div'); - setTimeout(() => { - div.innerHTML = ``; - }, 1000); - return div; -}; -Story5.storyName = 'Delayed render'; diff --git a/code/examples/server-kitchen-sink/stories/addons/a11y.stories.json b/code/examples/server-kitchen-sink/stories/addons/a11y.stories.json deleted file mode 100644 index 49afad6c39f3..000000000000 --- a/code/examples/server-kitchen-sink/stories/addons/a11y.stories.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "parameters": { - "options": { - "selectedPanel": "storybook/a11y/panel" - } - }, - "stories": [ - { - "name": "Default", - "parameters": { - "server": { - "id": "addons/a11y/default" - } - } - }, - { - "name": "Label", - "parameters": { - "server": { - "id": "addons/a11y/label" - } - } - }, - { - "name": "Disabled", - "parameters": { - "server": { - "id": "addons/a11y/disabled" - } - } - }, - { - "id": "Contrast", - "name": "Invalid contrast", - "parameters": { - "server": { - "id": "addons/a11y/contrast" - } - } - } - ] -} diff --git a/code/examples/web-components-kitchen-sink/src/stories/addons/a11y/addon-a11y.stories.ts b/code/examples/web-components-kitchen-sink/src/stories/addons/a11y/addon-a11y.stories.ts deleted file mode 100644 index 6490e0f36ca9..000000000000 --- a/code/examples/web-components-kitchen-sink/src/stories/addons/a11y/addon-a11y.stories.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { html } from 'lit'; -import type { Meta, StoryFn } from '@storybook/web-components'; - -const text = 'Testing the a11y addon'; - -export default { - title: 'Addons / A11y', - parameters: { - options: { selectedPanel: 'storybook/a11y/panel' }, - }, -} as Meta; - -export const Default: StoryFn = () => html``; -export const Label: StoryFn = () => html``; -export const Disabled: StoryFn = () => html``; -export const InvalidContrast: StoryFn = () => html` - -`; - -export const DelayedRender: StoryFn = () => { - const div = document.createElement('div'); - setTimeout(() => { - div.innerHTML = ``; - }, 1000); - return div; -}; From 1ea262fe543f854b7613077a8cf9cae7007e2aa3 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 8 Sep 2022 11:37:26 +0200 Subject: [PATCH 6/9] add a11y to sadnboxes --- scripts/sandbox.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/sandbox.ts b/scripts/sandbox.ts index 9c044b660dcb..d5ff62a659d6 100644 --- a/scripts/sandbox.ts +++ b/scripts/sandbox.ts @@ -14,6 +14,7 @@ import prompts from 'prompts'; import type { AbortController } from 'node-abort-controller'; import command from 'execa'; +import dedent from 'ts-dedent'; import { createOptions, getOptionsOrPrompt, OptionValues } from './utils/options'; import { executeCLIStep } from './utils/cli-step'; import { installYarn2, configureYarn2ForVerdaccio, addPackageResolutions } from './utils/yarn'; @@ -23,13 +24,13 @@ import { ConfigFile, readConfig, writeConfig } from '../code/lib/csf-tools'; import { babelParse } from '../code/lib/csf-tools/src/babelParse'; import TEMPLATES from '../code/lib/cli/src/repro-templates'; import { servePackages } from './utils/serve-packages'; -import dedent from 'ts-dedent'; type Template = keyof typeof TEMPLATES; const templates: Template[] = Object.keys(TEMPLATES) as any; const addons = ['a11y', 'storysource']; const defaultAddons = [ 'actions', + 'a11y', 'backgrounds', 'controls', 'docs', From 385f610f237d11734eaaccbe6acfebcf85c2a8a9 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 8 Sep 2022 11:53:46 +0200 Subject: [PATCH 7/9] Add a Svelte Html component --- code/renderers/react/template/components/Html.jsx | 1 + code/renderers/svelte/template/components/Html.svelte | 8 ++++++++ code/renderers/svelte/template/components/index.js | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 code/renderers/svelte/template/components/Html.svelte diff --git a/code/renderers/react/template/components/Html.jsx b/code/renderers/react/template/components/Html.jsx index c7fa14f3e584..974118ca5640 100644 --- a/code/renderers/react/template/components/Html.jsx +++ b/code/renderers/react/template/components/Html.jsx @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; +// eslint-disable-next-line react/no-danger export const Html = ({ contents }) =>
; Html.propTypes = { diff --git a/code/renderers/svelte/template/components/Html.svelte b/code/renderers/svelte/template/components/Html.svelte new file mode 100644 index 000000000000..b76ec4de7f1a --- /dev/null +++ b/code/renderers/svelte/template/components/Html.svelte @@ -0,0 +1,8 @@ + + +
{@html contents}>
diff --git a/code/renderers/svelte/template/components/index.js b/code/renderers/svelte/template/components/index.js index d2e5d492126f..9f7c09bcf792 100644 --- a/code/renderers/svelte/template/components/index.js +++ b/code/renderers/svelte/template/components/index.js @@ -1,5 +1,6 @@ import globalThis from 'global'; import Button from './Button.svelte'; +import Html from './Html.svelte'; -globalThis.Components = { Button }; +globalThis.Components = { Button, Html }; From 3c33ab04d4f509ef0ad2627373a597cff83d8be8 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 8 Sep 2022 12:11:33 +0200 Subject: [PATCH 8/9] Add a Html component for vue3 --- .../vue3/template/components/Html.vue | 20 +++++++++++++++++++ .../vue3/template/components/index.js | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 code/renderers/vue3/template/components/Html.vue diff --git a/code/renderers/vue3/template/components/Html.vue b/code/renderers/vue3/template/components/Html.vue new file mode 100644 index 000000000000..672c95661612 --- /dev/null +++ b/code/renderers/vue3/template/components/Html.vue @@ -0,0 +1,20 @@ + + + diff --git a/code/renderers/vue3/template/components/index.js b/code/renderers/vue3/template/components/index.js index bcf11c4fef18..3d396c684103 100644 --- a/code/renderers/vue3/template/components/index.js +++ b/code/renderers/vue3/template/components/index.js @@ -1,5 +1,6 @@ import globalThis from 'global'; import Button from './Button.vue'; +import Html from './Html.vue'; -globalThis.Components = { Button }; +globalThis.Components = { Button, Html }; From bc3bdee58ce22c8709b7746eb9899b1c0cb4e3a9 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 12 Sep 2022 16:25:50 +0300 Subject: [PATCH 9/9] refactor a bit, to improve tests --- code/addons/a11y/src/a11yRunner.ts | 4 +- .../template/stories/parameters.stories.ts | 42 +++++++++---------- .../a11y/template/stories/tests.stories.ts | 6 +-- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/code/addons/a11y/src/a11yRunner.ts b/code/addons/a11y/src/a11yRunner.ts index 1d6bd8b2f148..33440623ad17 100644 --- a/code/addons/a11y/src/a11yRunner.ts +++ b/code/addons/a11y/src/a11yRunner.ts @@ -69,9 +69,7 @@ const getParams = async (storyId: string): Promise => { return ( parameters.a11y || { config: {}, - options: { - restoreScroll: true, - }, + options: {}, } ); }; diff --git a/code/addons/a11y/template/stories/parameters.stories.ts b/code/addons/a11y/template/stories/parameters.stories.ts index acdf0d143c2c..159a6f07fd25 100644 --- a/code/addons/a11y/template/stories/parameters.stories.ts +++ b/code/addons/a11y/template/stories/parameters.stories.ts @@ -1,55 +1,55 @@ import globalThis from 'global'; export default { - component: globalThis.Components.Button, + component: globalThis.Components.Html, args: { - children: 'Click Me!', + contents: '', }, parameters: { chromatic: { disable: true }, }, }; -export const Basic = {}; - -export const Violation = { +export const Options = { args: { - // empty on purpose to get a button with no text - children: '', + contents: + '', }, -}; - -export const Checks = { parameters: { a11y: { config: {}, options: { checks: { - 'color-contrast': { options: { noScroll: true } }, + 'color-contrast': { enabled: false }, }, - restoreScroll: true, }, }, }, }; -export const Targetted = { +export const Config = { + args: { + contents: + '', + }, parameters: { a11y: { - element: 'button', + config: { + rules: [{ id: 'avoid-inline-spacing', options: {} }], + disableOtherRules: true, + }, + options: {}, }, }, }; -export const Blank = { +export const Targetted = { + args: { + contents: '', + }, parameters: { a11y: { - config: { - disableOtherRules: true, - // @ts-ignore - rules: [], - }, - options: {}, + element: '.custom-target', }, }, }; diff --git a/code/addons/a11y/template/stories/tests.stories.ts b/code/addons/a11y/template/stories/tests.stories.ts index 03346296518a..6c729ad66e05 100644 --- a/code/addons/a11y/template/stories/tests.stories.ts +++ b/code/addons/a11y/template/stories/tests.stories.ts @@ -3,7 +3,7 @@ import globalThis from 'global'; export default { component: globalThis.Components.Html, args: { - content: '', + contents: '', }, parameters: { chromatic: { disable: true }, @@ -12,7 +12,7 @@ export default { export const Violations = { args: { - content: ` + contents: `

empty heading

@@ -39,7 +39,7 @@ export const Violations = { export const Passes = { args: { - content: ` + contents: `

heading

heading 1