From 3e8abc7798eb9778d9f42af50cf5fd9c0bd5f97f Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Tue, 18 Mar 2025 17:05:51 +0100 Subject: [PATCH] Refactor a11y addon panel, update its layout and implement deeplinking --- .../a11y/src/components/A11YPanel.stories.tsx | 78 +------ code/addons/a11y/src/components/A11YPanel.tsx | 55 ++++- .../a11y/src/components/A11yContext.tsx | 54 ++++- .../a11y/src/components/Report/Details.tsx | 206 ++++++++++++++++++ .../a11y/src/components/Report/Elements.tsx | 65 ------ .../src/components/Report/HighlightToggle.tsx | 32 --- .../a11y/src/components/Report/Info.tsx | 33 --- .../a11y/src/components/Report/Instances.tsx | 62 ------ .../a11y/src/components/Report/Item.tsx | 76 ------- .../{index.stories.tsx => Report.stories.tsx} | 7 +- .../a11y/src/components/Report/Report.tsx | 86 ++++++++ .../a11y/src/components/Report/index.tsx | 25 --- code/addons/a11y/src/components/Tabs.tsx | 8 +- .../Report/results.ts => results.mock.ts} | 2 +- code/yarn.lock | 124 ++++++++++- 15 files changed, 521 insertions(+), 392 deletions(-) create mode 100644 code/addons/a11y/src/components/Report/Details.tsx delete mode 100644 code/addons/a11y/src/components/Report/Elements.tsx delete mode 100644 code/addons/a11y/src/components/Report/HighlightToggle.tsx delete mode 100644 code/addons/a11y/src/components/Report/Info.tsx delete mode 100644 code/addons/a11y/src/components/Report/Instances.tsx delete mode 100644 code/addons/a11y/src/components/Report/Item.tsx rename code/addons/a11y/src/components/Report/{index.stories.tsx => Report.stories.tsx} (87%) create mode 100644 code/addons/a11y/src/components/Report/Report.tsx delete mode 100644 code/addons/a11y/src/components/Report/index.tsx rename code/addons/a11y/src/{components/Report/results.ts => results.mock.ts} (99%) diff --git a/code/addons/a11y/src/components/A11YPanel.stories.tsx b/code/addons/a11y/src/components/A11YPanel.stories.tsx index 353fddeaa1d..ee57ae4c7d5 100644 --- a/code/addons/a11y/src/components/A11YPanel.stories.tsx +++ b/code/addons/a11y/src/components/A11YPanel.stories.tsx @@ -2,11 +2,11 @@ import React from 'react'; import type { Meta, StoryObj } from '@storybook/react-vite'; -import type axe from 'axe-core'; import { ManagerContext } from 'storybook/manager-api'; import { fn } from 'storybook/test'; import { styled } from 'storybook/theming'; +import { results } from '../results.mock'; import { A11YPanel } from './A11YPanel'; import { A11yContext } from './A11yContext'; import type { A11yContextStore } from './A11yContext'; @@ -52,61 +52,6 @@ export default meta; type Story = StoryObj; -const violations: axe.Result[] = [ - { - id: 'aria-command-name', - impact: 'serious', - tags: ['cat.aria', 'wcag2a', 'wcag412', 'TTv5', 'TT6.a', 'EN-301-549', 'EN-9.4.1.2', 'ACT'], - description: 'Ensures every ARIA button, link and menuitem has an accessible name', - help: 'ARIA commands must have an accessible name', - helpUrl: 'https://dequeuniversity.com/rules/axe/4.8/aria-command-name?application=axeAPI', - nodes: [ - { - any: [ - { - id: 'has-visible-text', - data: null, - relatedNodes: [], - impact: 'serious', - message: 'Element does not have text that is visible to screen readers', - }, - { - id: 'aria-label', - data: null, - relatedNodes: [], - impact: 'serious', - message: 'aria-label attribute does not exist or is empty', - }, - { - id: 'aria-labelledby', - data: null, - relatedNodes: [], - impact: 'serious', - message: - 'aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty', - }, - { - id: 'non-empty-title', - data: { - messageKey: 'noAttr', - }, - relatedNodes: [], - impact: 'serious', - message: 'Element has no title attribute', - }, - ], - all: [], - none: [], - impact: 'serious', - html: '
', - target: ['.css-12jpz5t'], - failureSummary: - 'Fix any of the following:\n Element does not have text that is visible to screen readers\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute', - }, - ], - }, -]; - const Template = (args: Pick) => ( @@ -177,18 +124,7 @@ export const Running: Story = { export const ReadyWithResults: Story = { render: () => { - return ( -