Skip to content

Commit 8f78880

Browse files
committed
[EuiAvatar] Windows high contrast mode tweaks
- render a border (in non-forced colors, background color should be sufficient) - force icons/SVGs to full shade to match forced color mode
1 parent 92ab05a commit 8f78880

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

11 Bytes
Loading
12 Bytes
Loading

packages/eui/src/components/avatar/avatar.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
euiPaletteColorBlindBehindText,
1616
toInitials,
1717
useEuiMemoizedStyles,
18+
useEuiTheme,
1819
} from '../../services';
1920
import { IconType, EuiIcon, IconSize, IconColor } from '../icon';
2021

@@ -126,10 +127,12 @@ export const EuiAvatar: FunctionComponent<EuiAvatarProps> = ({
126127
}) => {
127128
checkValidInitials(initials);
128129
const { casing = type === 'space' ? 'none' : 'uppercase', ...rest } = props;
130+
const { highContrastMode, euiTheme } = useEuiTheme();
129131

130132
const isPlain = color === 'plain';
131133
const isSubdued = color === 'subdued';
132134
const isNamedColor = isPlain || isSubdued || color === null;
135+
const isForcedColors = highContrastMode === 'forced';
133136

134137
const classes = classNames(
135138
'euiAvatar',
@@ -174,20 +177,28 @@ export const EuiAvatar: FunctionComponent<EuiAvatarProps> = ({
174177
}
175178
}, [imageUrl, color, isNamedColor, name.length]);
176179

180+
const highContrastBorder = useMemo(
181+
// Render a border since background-colors are ignored in Windows forced contrast themes
182+
() => (isForcedColors ? { border: euiTheme.border.thin } : undefined),
183+
[isForcedColors, euiTheme]
184+
);
185+
177186
const iconCustomColor = useMemo(() => {
187+
// Force icons to single colors in forced high contrast mode
188+
if (isForcedColors) return euiTheme.colors.fullShade;
178189
// `null` allows icons to keep their default color (e.g. app icons)
179190
if (iconColor === null) return undefined;
180191
// Otherwise continue to pass on `iconColor`
181192
if (iconColor) return iconColor;
182193
// Fall back to the adjusted text color if it exists
183194
return avatarStyle?.color;
184-
}, [iconColor, avatarStyle?.color]);
195+
}, [iconColor, avatarStyle?.color, isForcedColors, euiTheme]);
185196

186197
return (
187198
<div
188199
css={cssStyles}
189200
className={classes}
190-
style={{ ...style, ...avatarStyle }}
201+
style={{ ...style, ...avatarStyle, ...highContrastBorder }}
191202
aria-label={isDisabled ? undefined : name}
192203
role={isDisabled ? 'presentation' : 'img'}
193204
title={name}

0 commit comments

Comments
 (0)