Skip to content

Commit 394210d

Browse files
authored
fix: resolve wcag2aa color contrast issues (#367)
1 parent bf17028 commit 394210d

File tree

9 files changed

+53
-23
lines changed

9 files changed

+53
-23
lines changed

package-lock.json

Lines changed: 23 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@ory/client": "1.19.0",
4545
"@playwright/experimental-ct-react": "1.46.0",
4646
"@preact/preset-vite": "2.5.0",
47+
"@storybook/addon-a11y": "8.3.0",
4748
"@storybook/addon-docs": "8.3.0",
4849
"@storybook/addon-essentials": "8.3.0",
4950
"@storybook/addon-interactions": "8.3.0",

packages/elements-react/.storybook/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import svgr from "vite-plugin-svgr"
1010

1111
const config: StorybookConfig = {
1212
stories: ["../**/*.stories.@(ts|tsx)"],
13-
addons: ["@storybook/addon-essentials", "@storybook/addon-interactions"],
13+
addons: [
14+
"@storybook/addon-essentials",
15+
"@storybook/addon-interactions",
16+
"@storybook/addon-a11y",
17+
],
1418
framework: {
1519
name: "@storybook/react-vite",
1620
options: {},

packages/elements-react/.storybook/preview.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ const preview: Preview = {
2222
date: /Date$/i,
2323
},
2424
},
25+
26+
a11y: {
27+
config: {},
28+
/*
29+
* Axe's options parameter
30+
* See https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter
31+
* to learn more about the available options.
32+
*/
33+
options: {
34+
// TODO: try to meet "wcag2aaa" (error messages are don't have enough contrast)
35+
// runOnly: ["wcag2a", "wcag2aa", "best-practice"],
36+
},
37+
},
2538
},
2639
}
2740

packages/elements-react/src/theme/default/components/form/image.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
import { OryNodeImageProps } from "@ory/elements-react"
55

6-
export function DefaultImage({ attributes }: OryNodeImageProps) {
6+
export function DefaultImage({ attributes, node }: OryNodeImageProps) {
77
return (
88
<figure>
9-
<img {...attributes} />
9+
<img {...attributes} alt={node.meta.label?.text || ""} />
1010
</figure>
1111
)
1212
}

packages/elements-react/src/theme/default/components/form/input.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function PasswordToggle({
114114
onClick={handleClick}
115115
className="absolute right-0 h-full w-12 flex items-center justify-center"
116116
type="button"
117+
aria-label="Toggle password visibility"
117118
>
118119
{shown ? <EyeOff /> : <Eye />}
119120
</button>

packages/elements-react/src/theme/default/components/form/social.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export function DefaultButtonSocial({
9090
}
9191
}, [isSubmitting, setClicked])
9292

93+
const label = node.meta.label
94+
? uiTextToFormattedMessage(node.meta.label, intl)
95+
: ""
96+
9397
return (
9498
<button
9599
className="gap-3 border border-button-social-border-default bg-button-social-background-default hover:bg-button-social-background-hover transition-colors rounded-buttons flex items-center justify-center px-4 py-[13px] loading:bg-button-social-background-disabled loading:border-button-social-border-disabled loading:text-button-social-foreground-disabled hover:text-button-social-foreground-hover"
@@ -101,6 +105,7 @@ export function DefaultButtonSocial({
101105
onClick={localOnClick}
102106
data-loading={clicked}
103107
disabled={isSubmitting}
108+
aria-label={label}
104109
>
105110
<span className="size-5 relative">
106111
{!clicked ? (
@@ -118,7 +123,7 @@ export function DefaultButtonSocial({
118123
{showLabel && node.meta.label ? (
119124
<>
120125
<span className="grow text-center font-medium leading-none text-button-social-foreground-default">
121-
{uiTextToFormattedMessage(node.meta.label, intl)}
126+
{label}
122127
</span>
123128
<span className="size-5 block"></span>
124129
</>

packages/elements-react/src/theme/default/components/ui/user-menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const UserMenu = ({ session }: UserMenuProps) => {
2929
return (
3030
<DropdownMenu>
3131
<DropdownMenuTrigger asChild>
32-
<UserAvatar initials={initials} />
32+
<UserAvatar initials={initials} title="User Menu" />
3333
</DropdownMenuTrigger>
3434
<DropdownMenuContent>
3535
<DropdownMenuLabel className="flex gap-3 px-5 py-4.5">

packages/elements-react/tailwind/generated/default-variables.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
--ui-900: #0f172a;
1515
--ui-950: #020617;
1616
--ui-black: #000000;
17-
--ui-danger: #ef4444;
17+
--ui-danger: #dc2626;
1818
--ui-success: #22c55e;
1919
--ui-transparent: #ffffff00;
2020
--ui-warning: #eab308;

0 commit comments

Comments
 (0)