@@ -15,6 +15,7 @@ import {
1515 euiPaletteColorBlindBehindText ,
1616 toInitials ,
1717 useEuiMemoizedStyles ,
18+ useEuiTheme ,
1819} from '../../services' ;
1920import { 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