Skip to content

Commit cf0ad33

Browse files
authored
[dev-overlay] Fix outstanding a11y issues reported by Axe (#80290)
Adds labels to buttons that had no discernible text. The automated tests via `test-storybook` seem to ignore `parameters.a11y.config.rules` so we can't leverage `test-storybook` in CI. I can't even use `parameters.a11y.test`. We need `parameters.a11y.config.rules` since some of the color-contrast violations are either minor (just slightly below threshold) or false-positives either because our background is misconfigured in automated tests, or background is not detected properly.
1 parent c151f89 commit cf0ad33

File tree

10 files changed

+94
-10
lines changed

10 files changed

+94
-10
lines changed

packages/next/.storybook/preview.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ const preview: Preview = {
1818
parameters: {
1919
a11y: {
2020
element: 'nextjs-portal',
21+
config: {
22+
standards: {
23+
ariaAttrs: {
24+
'aria-modal': {
25+
global: true,
26+
},
27+
},
28+
},
29+
rules: [
30+
{
31+
// It's incredibly hard to find a code highlighting theme that works
32+
// for both light and dark themes and passes WCAG color contrast.
33+
// These kind of tests should really only fail when you regress
34+
// on a value below threshold.
35+
id: 'color-contrast',
36+
selector: '.code-frame-lines',
37+
enabled: false,
38+
},
39+
],
40+
},
2141
},
2242
controls: {
2343
matchers: {

packages/next/src/client/components/react-dev-overlay/ui/components/call-stack-frame/call-stack-frame.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ const meta: Meta<typeof CallStackFrame> = {
99
backgrounds: {
1010
default: 'background-100-dark',
1111
},
12+
a11y: {
13+
config: {
14+
rules: [
15+
{
16+
id: 'color-contrast',
17+
// Manual testing shows no violation.
18+
// TODO: We might have setup more explicit backgrounds depending on theme.
19+
enabled: false,
20+
},
21+
],
22+
},
23+
},
1224
},
1325
decorators: [withShadowPortal],
1426
}

packages/next/src/client/components/react-dev-overlay/ui/components/call-stack-frame/call-stack-frame.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ export const CallStackFrame: React.FC<{
2323
: undefined
2424
)
2525

26-
// Format method to strip out the webpack layer prefix.
27-
// e.g. (app-pages-browser)/./app/page.tsx -> ./app/page.tsx
28-
const formattedMethod = f.methodName.replace(/^\([\w-]+\)\//, '')
29-
3026
// Formatted file source could be empty. e.g. <anonymous> will be formatted to empty string,
3127
// we'll skip rendering the frame in this case.
3228
const fileSource = getFrameSource(f)
@@ -42,9 +38,13 @@ export const CallStackFrame: React.FC<{
4238
data-nextjs-call-stack-frame-ignored={frame.ignored}
4339
>
4440
<div className="call-stack-frame-method-name">
45-
<HotlinkedText text={formattedMethod} />
41+
<HotlinkedText text={f.methodName} />
4642
{hasSource && (
47-
<button onClick={open} className="open-in-editor-button">
43+
<button
44+
onClick={open}
45+
className="open-in-editor-button"
46+
aria-label={`Open ${f.methodName} in editor`}
47+
>
4848
<ExternalIcon width={16} height={16} />
4949
</button>
5050
)}

packages/next/src/client/components/react-dev-overlay/ui/components/errors/call-stack/call-stack.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ const meta: Meta<typeof CallStack> = {
99
backgrounds: {
1010
default: 'background-100-dark',
1111
},
12+
a11y: {
13+
config: {
14+
rules: [
15+
{
16+
id: 'color-contrast',
17+
// Manual testing shows no violation.
18+
// TODO: We might have setup more explicit backgrounds depending on theme.
19+
enabled: false,
20+
},
21+
],
22+
},
23+
},
1224
},
1325
decorators: [withShadowPortal],
1426
}

packages/next/src/client/components/react-dev-overlay/ui/components/errors/dev-tools-indicator/next-logo.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const meta: Meta<typeof NextLogo> = {
88
layout: 'centered',
99
},
1010
args: {
11+
'aria-label': 'Open Next.js DevTools',
1112
onClick: () => console.log('Clicked!'),
1213
},
1314
decorators: [withShadowPortal],

packages/next/src/client/components/react-dev-overlay/ui/components/errors/error-message/error-message.stories.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ const meta: Meta<typeof ErrorMessage> = {
66
component: ErrorMessage,
77
parameters: {
88
layout: 'fullscreen',
9+
backgrounds: {
10+
default: 'background-100-light',
11+
},
12+
a11y: {
13+
config: {
14+
rules: [
15+
{
16+
id: 'color-contrast',
17+
// Manual testing shows no violation.
18+
// TODO: We might have setup more explicit backgrounds depending on theme.
19+
enabled: false,
20+
},
21+
],
22+
},
23+
},
924
},
1025
decorators: [withShadowPortal],
1126
}

packages/next/src/client/components/react-dev-overlay/ui/components/hydration-diff/diff-view.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ import { CollapseIcon } from '../../icons/collapse-icon'
5050
*/
5151
export function PseudoHtmlDiff({
5252
reactOutputComponentDiff,
53-
...props
5453
}: {
5554
reactOutputComponentDiff: string
56-
} & React.HTMLAttributes<HTMLPreElement>) {
55+
}) {
5756
const [isDiffCollapsed, toggleCollapseHtml] = useState(true)
5857

5958
const htmlComponents = useMemo(() => {
@@ -120,12 +119,14 @@ export function PseudoHtmlDiff({
120119
data-nextjs-container-errors-pseudo-html-collapse={isDiffCollapsed}
121120
>
122121
<button
122+
aria-expanded={!isDiffCollapsed}
123+
aria-label="complete Component Stack"
123124
data-nextjs-container-errors-pseudo-html-collapse-button
124125
onClick={() => toggleCollapseHtml(!isDiffCollapsed)}
125126
>
126127
<CollapseIcon collapsed={isDiffCollapsed} />
127128
</button>
128-
<pre {...props}>
129+
<pre className="nextjs__container_errors__component-stack">
129130
<code>{htmlComponents}</code>
130131
</pre>
131132
</div>

packages/next/src/client/components/react-dev-overlay/ui/components/terminal/terminal.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ const meta: Meta<typeof Terminal> = {
66
component: Terminal,
77
parameters: {
88
layout: 'fullscreen',
9+
a11y: {
10+
config: {
11+
rules: [
12+
{
13+
id: 'color-contrast',
14+
// Manual testing shows no violation.
15+
// TODO: We might have setup more explicit backgrounds depending on theme.
16+
enabled: false,
17+
},
18+
],
19+
},
20+
},
921
},
1022
decorators: [withShadowPortal],
1123
}

packages/next/src/client/components/react-dev-overlay/ui/container/errors.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ export function Errors({
202202

203203
{errorDetails.reactOutputComponentDiff ? (
204204
<PseudoHtmlDiff
205-
className="nextjs__container_errors__component-stack"
206205
reactOutputComponentDiff={errorDetails.reactOutputComponentDiff || ''}
207206
/>
208207
) : null}

packages/next/src/client/components/react-dev-overlay/ui/dev-overlay.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ const meta: Meta<typeof DevOverlay> = {
1616
component: DevOverlay,
1717
parameters: {
1818
layout: 'fullscreen',
19+
a11y: {
20+
config: {
21+
rules: [
22+
{
23+
id: 'color-contrast',
24+
// Manual testing shows no violation.
25+
// TODO: We might have setup more explicit backgrounds depending on theme.
26+
enabled: false,
27+
},
28+
],
29+
},
30+
},
1931
},
2032
}
2133

0 commit comments

Comments
 (0)