Skip to content

Commit a878119

Browse files
committed
feat: improve form controls border contrast for accessibility
The default border colors for form controls in the default theme in Zendesk Garden don't meet the minimum 3:1 contrast ratio against the background. We apply a custom theme override to increase the contrast of these borders, following the guidelines provided by the Garden team in an internal doc. By default, Garden sets the `grey.300` color as the default border color in the light theme, and then it is increased by 100 for form controls, which is not sufficient, providing only 2:1 contrast ratio. To reach the 3:1 ratio, we need to use `grey.600` and so we apply an offset of 300. We also enhance the hover state border color, which by default is less prominent when the border color is darker. We also update the `$high-contrast-border-color` Sass variable to match the new border color used in the theme override.
1 parent 9be8842 commit a878119

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/modules/shared/garden-theme/createTheme.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IButtonProps } from "@zendeskgarden/react-buttons";
22
import type { IGardenTheme } from "@zendeskgarden/react-theming";
3-
import { DEFAULT_THEME } from "@zendeskgarden/react-theming";
3+
import { DEFAULT_THEME, getColor } from "@zendeskgarden/react-theming";
44
import { css } from "styled-components";
55

66
export interface Settings {
@@ -14,6 +14,30 @@ export interface Settings {
1414
}
1515

1616
export function createTheme(settings: Settings): IGardenTheme {
17+
const accessibleFormControls = css`
18+
/* Boost default border contrast - use :not() to preserve validation colors */
19+
&:not([aria-invalid="true"]) {
20+
border-color: ${(p) =>
21+
getColor({
22+
theme: p.theme,
23+
variable: "border.default",
24+
dark: { offset: -100 },
25+
light: { offset: 300 },
26+
})};
27+
}
28+
29+
/* Enhanced hover state */
30+
&:hover:not([aria-invalid="true"]) {
31+
border-color: ${(p) =>
32+
getColor({
33+
theme: p.theme,
34+
variable: "border.primaryEmphasis",
35+
dark: { offset: -100 },
36+
light: { offset: 100 },
37+
})};
38+
}
39+
`;
40+
1741
return {
1842
...DEFAULT_THEME,
1943
rtl: document.dir === "rtl",
@@ -56,6 +80,10 @@ export function createTheme(settings: Settings): IGardenTheme {
5680
color: ${settings.brand_text_color};
5781
`}
5882
`,
83+
"forms.input": accessibleFormControls,
84+
"forms.faux_input": accessibleFormControls,
85+
"forms.textarea": accessibleFormControls,
86+
"dropdowns.combobox.trigger": accessibleFormControls,
5987
},
6088
};
6189
}

styles/_variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $font-size-navigation: 14px;
1313
$font-size-small: 13px;
1414
$font-size-smaller: 11px;
1515

16-
$high-contrast-border-color: #87929D; // maintains a 3:1 contrast ratio with default background color (#FFF). Use for controls and inputs
16+
$high-contrast-border-color: #848F99; // maintains a 3:1 contrast ratio with default background color (#FFF). Use for controls and inputs
1717
$low-contrast-border-color: #ddd; // less than 3:1 contrast ratio with default background color. Use for elements that do not require user interaction
1818
$menu-border-color: #d8dcde;
1919

0 commit comments

Comments
 (0)