Skip to content

Commit 8912c05

Browse files
committed
[PR feedback] Form clear button - respect windows theme colors more
1 parent 036e2a9 commit 8912c05

2 files changed

Lines changed: 34 additions & 18 deletions

File tree

packages/eui/src/components/form/form_control_layout/form_control_layout_clear_button.styles.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { css } from '@emotion/react';
1010

11+
import { logicalSizeCSS, mathWithUnits } from '../../../global_styling';
1112
import { UseEuiTheme } from '../../../services';
1213

1314
export const EuiFormControlLayoutClearButtonStyles = ({
@@ -16,38 +17,52 @@ export const EuiFormControlLayoutClearButtonStyles = ({
1617
highContrastMode,
1718
}: UseEuiTheme) => {
1819
const backgroundColor =
19-
highContrastMode === 'forced'
20-
? euiTheme.colors.fullShade
21-
: colorMode === 'DARK' || highContrastMode // mediumShade is not sufficient WCAG contrast
20+
colorMode === 'DARK' || highContrastMode // mediumShade is not sufficient WCAG contrast
2221
? euiTheme.colors.darkShade
2322
: euiTheme.colors.mediumShade;
2423

2524
return {
2625
euiFormControlLayoutClearButton: css`
2726
pointer-events: all;
28-
background-color: ${backgroundColor};
29-
${highContrastMode === 'forced' ? 'forced-color-adjust: none;' : ''}
27+
display: flex;
28+
justify-content: center;
29+
align-items: center;
3030
border-radius: 50%;
31-
line-height: 0; /* ensures the icon stays vertically centered */
31+
/* Windows high contrast themes ignore background-color, so we use border to color the button instead for better support */
32+
border-style: solid;
33+
border-color: ${backgroundColor};
3234
3335
&:disabled {
3436
cursor: not-allowed;
3537
background-color: ${euiTheme.colors.disabled};
3638
}
3739
`,
3840

39-
euiFormControlLayoutClearButton__icon: css`
40-
transform: scale(0.5);
41-
fill: ${euiTheme.colors.emptyShade};
42-
stroke: ${euiTheme.colors.emptyShade};
43-
`,
4441
size: {
45-
s: css`
46-
stroke-width: ${euiTheme.size.xs};
42+
s: `
43+
${logicalSizeCSS(euiTheme.size.m)}
44+
border-width: ${mathWithUnits(euiTheme.size.m, (x) => x / 2)};
45+
`,
46+
m: `
47+
${logicalSizeCSS(euiTheme.size.base)}
48+
border-width: ${mathWithUnits(euiTheme.size.base, (x) => x / 2)};
4749
`,
48-
m: css`
49-
stroke-width: ${euiTheme.size.xxs};
50+
},
51+
52+
icon: {
53+
euiFormControlLayoutClearButton__icon: css`
54+
transform: scale(0.5);
55+
fill: ${euiTheme.colors.emptyShade};
56+
stroke: ${euiTheme.colors.emptyShade};
5057
`,
58+
size: {
59+
s: css`
60+
stroke-width: ${euiTheme.size.xs};
61+
`,
62+
m: css`
63+
stroke-width: ${euiTheme.size.xxs};
64+
`,
65+
},
5166
},
5267
};
5368
};

packages/eui/src/components/form/form_control_layout/form_control_layout_clear_button.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ export const EuiFormControlLayoutClearButton: FunctionComponent<
2626
> = ({ className, onClick, size = 'm', ...rest }) => {
2727
const classes = classNames('euiFormControlLayoutClearButton', className);
2828
const styles = useEuiMemoizedStyles(EuiFormControlLayoutClearButtonStyles);
29+
const cssStyles = [styles.euiFormControlLayoutClearButton, styles.size[size]];
2930
const iconStyles = [
30-
styles.euiFormControlLayoutClearButton__icon,
31-
styles.size[size],
31+
styles.icon.euiFormControlLayoutClearButton__icon,
32+
styles.icon.size[size],
3233
];
3334

3435
const ariaLabel = useEuiI18n(
@@ -39,7 +40,7 @@ export const EuiFormControlLayoutClearButton: FunctionComponent<
3940
return (
4041
<button
4142
type="button"
42-
css={styles.euiFormControlLayoutClearButton}
43+
css={cssStyles}
4344
className={classes}
4445
onClick={onClick}
4546
aria-label={ariaLabel}

0 commit comments

Comments
 (0)