Back to Storybook

Addon A11y Parameter Example

docs/_snippets/addon-a11y-parameter-example.md

10.3.611.1 KB
Original Source
ts
import type { Meta, StoryObj } from '@storybook/angular';

import { Button } from './button.component';

const meta: Meta<Button> = {
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
};
export default meta;

type Story = StoryObj<Button>;

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary: Story = {
  args: { primary: true },
};

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail: Story = {
  parameters: {
    a11y: { test: 'todo' },
  },
};
ts
import preview from '../.storybook/preview';

import { Button } from './button.component';

const meta = preview.meta({
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
});

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = meta.story({
  args: { primary: true },
});

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = meta.story({
  parameters: {
    a11y: { test: 'todo' },
  },
});
ts
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { Meta, StoryObj } from '@storybook/your-framework';

import { Button } from './Button';

const meta = {
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
} satisfies Meta<typeof Button>;
export default meta;

type Story = StoryObj<typeof meta>;

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary: Story = {
  args: { primary: true },
};

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail: Story = {
  parameters: {
    a11y: { test: 'todo' },
  },
};
js
import { Button } from './Button';

export default {
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
};

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = {
  args: { primary: true },
};

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = {
  parameters: {
    a11y: { test: 'todo' },
  },
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Button from './Button.svelte';

  const { Story } = defineMeta({
    component: Button,
    parameters: {
      // ๐Ÿ‘‡ Applies to all stories in this file
      a11y: { test: 'error' },
    },
  });
</script>

<!-- ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations -->
<Story
  name="Primary"
  args={{ primary: true }}
/>

<!-- ๐Ÿ‘‡ This story will not fail on accessibility violations
        (but will still run the tests and show warnings) -->
<Story
  name="NoA11yFail"
  parameters={{
    a11y: { test: 'todo' },
  }}
/>
ts
// Replace your-framework with the framework you are using, e.g. sveltekit or svelte-vite
import type { Meta, StoryObj } from '@storybook/your-framework';

import Button from './Button.svelte';

const meta = {
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
} satisfies Meta<typeof Button>;
export default meta;

type Story = StoryObj<typeof meta>;

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary: Story = {
  args: { primary: true },
};

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail: Story = {
  parameters: {
    a11y: { test: 'todo' },
  },
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Button from './Button.svelte';

  const { Story } = defineMeta({
    component: Button,
    parameters: {
      // ๐Ÿ‘‡ Applies to all stories in this file
      a11y: { test: 'error' },
    },
  });
</script>

<!-- ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations -->
<Story
  name="Primary"
  args={{ primary: true }}
/>

<!-- ๐Ÿ‘‡ This story will not fail on accessibility violations
        (but will still run the tests and show warnings) -->
<Story
  name="NoA11yFail"
  parameters={{
    a11y: { test: 'todo' },
  }}
/>
js
import Button from './Button.svelte';

export default {
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
};

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = {
  args: { primary: true },
};

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = {
  parameters: {
    a11y: { test: 'todo' },
  },
};
ts
import type { Meta, StoryObj } from '@storybook/web-components-vite';

const meta: Meta = {
  component: 'demo-button',
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
};
export default meta;

type Story = StoryObj;

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary: Story = {
  args: { primary: true },
};

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail: Story = {
  parameters: {
    a11y: { test: 'todo' },
  },
};
js
export default {
  component: 'demo-button',
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
};

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = {
  args: { primary: true },
};

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = {
  parameters: {
    a11y: { test: 'todo' },
  },
};
js
import preview from '../.storybook/preview';

const meta = preview.meta({
  component: 'demo-button',
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
});

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = meta.story({
  args: { primary: true },
});

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = meta.story({
  parameters: {
    a11y: { test: 'todo' },
  },
});
ts
import preview from '../.storybook/preview';

const meta = preview.meta({
  component: 'demo-button',
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
});

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = meta.story({
  args: { primary: true },
});

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = meta.story({
  parameters: {
    a11y: { test: 'todo' },
  },
});
ts
import preview from '../.storybook/preview';

import { Button } from './Button';

const meta = preview.meta({
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
});

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = meta.story({
  args: { primary: true },
});

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = meta.story({
  parameters: {
    a11y: { test: 'todo' },
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import { Button } from './Button';

const meta = preview.meta({
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
});

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = meta.story({
  args: { primary: true },
});

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = meta.story({
  parameters: {
    a11y: { test: 'todo' },
  },
});
ts
import preview from '../.storybook/preview';

import Button from './Button.vue';

const meta = preview.meta({
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
});

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = meta.story({
  args: { primary: true },
});

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = meta.story({
  parameters: {
    a11y: { test: 'todo' },
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import Button from './Button.vue';

const meta = preview.meta({
  component: Button,
  parameters: {
    // ๐Ÿ‘‡ Applies to all stories in this file
    a11y: { test: 'error' },
  },
});

// ๐Ÿ‘‡ This story will use the 'error' value and fail on accessibility violations
export const Primary = meta.story({
  args: { primary: true },
});

// ๐Ÿ‘‡ This story will not fail on accessibility violations
//    (but will still run the tests and show warnings)
export const NoA11yFail = meta.story({
  parameters: {
    a11y: { test: 'todo' },
  },
});