Skip to content

Commit 7dbbca6

Browse files
committed
Fix contrast & styling for invalid input placeholders
1 parent 85e3abe commit 7dbbca6

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/components/common/inputs.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ const invalidTextCss = css`
120120
border-color: ${p => p.theme.mainColor};
121121
background-color: ${p => p.theme.warningBackground};
122122
}
123+
124+
&::placeholder {
125+
color: ${p => p.theme.inputWarningPlaceholder};
126+
}
123127
`;
124128

125129
type TextInputProps = React.InputHTMLAttributes<HTMLInputElement> & {

src/styles.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const lightTheme = {
7272
inputBorder: darkGrey,
7373
inputColor: inkGrey,
7474
inputPlaceholderColor: darkishGrey,
75+
inputWarningPlaceholder: '#8c5c1d', // Mix of warning + inkGrey
7576

7677
highlightBackground: white,
7778
highlightColor: inkGrey,
@@ -126,6 +127,7 @@ export const darkTheme = {
126127
inputBorder: darkishGrey,
127128
inputColor: white,
128129
inputPlaceholderColor: mediumGrey,
130+
inputWarningPlaceholder: '#e8b978', // Mix of warning + white
129131

130132
highlightBackground: darkishGrey,
131133
highlightColor: white,
@@ -201,6 +203,7 @@ export const highContrastTheme = {
201203
inputBorder: '#aaa',
202204
inputColor: '#000000',
203205
inputPlaceholderColor: '#444',
206+
inputWarningPlaceholder: '#e1b374', // Mix of warning + white
204207

205208
highlightBackground: '#ffffff',
206209
highlightColor: '#000',

test/unit/styles.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ import { expect } from '../test-setup';
6868
);
6969
});
7070

71+
it("should have sufficient input warning contrast", () => {
72+
const mainColor = theme.inputWarningPlaceholder;
73+
74+
// Warning background is #RRGGBBAA, so we need to mix to check the real bg colour:
75+
const warningBackgroundColor = theme.warningBackground.slice(0, 7);
76+
const warningBackgroundOpacity = theme.warningBackground.slice(7, 9);
77+
const warningBackgroundRatio = parseInt(warningBackgroundOpacity, 16) / 255;
78+
79+
const bgColor = polished.mix(
80+
warningBackgroundRatio,
81+
warningBackgroundColor,
82+
theme.mainBackground
83+
);
84+
85+
const contrast = polished.getContrast(mainColor, bgColor);
86+
expect(contrast).to.be.greaterThan(normalContrastTarget,
87+
`Constrast for ${mainColor}/${bgColor} was only ${contrast}`
88+
);
89+
});
90+
7191
it("should have sufficient input placeholder contrast", () => {
7292
const mainColor = theme.inputPlaceholderColor;
7393
const bgColor = theme.inputBackground;

0 commit comments

Comments
 (0)