Skip to content

Commit 0ad67e1

Browse files
feat: replace title with tooltip
1 parent e34e0bc commit 0ad67e1

169 files changed

Lines changed: 5528 additions & 3862 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/eui/src/components/avatar/__snapshots__/avatar.test.tsx.snap

Lines changed: 365 additions & 250 deletions
Large diffs are not rendered by default.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import React from 'react';
10+
import { fireEvent } from '@testing-library/react';
1011
import { shouldRenderCustomStyles } from '../../test/internal';
1112
import { requiredProps } from '../../test/required_props';
1213
import { render } from '../../test/rtl';
@@ -168,6 +169,20 @@ describe('EuiAvatar', () => {
168169
});
169170
});
170171

172+
describe('tooltip', () => {
173+
it('shows a tooltip with the avatar name on hover', () => {
174+
const { getByRole, queryByRole } = render(<EuiAvatar name="Jane Doe" />);
175+
expect(queryByRole('tooltip')).not.toBeInTheDocument();
176+
fireEvent.mouseOver(getByRole('img'));
177+
expect(getByRole('tooltip')).toHaveTextContent('Jane Doe');
178+
});
179+
180+
it('is keyboard focusable', () => {
181+
const { getByRole } = render(<EuiAvatar name="Jane Doe" />);
182+
expect(getByRole('img')).toHaveAttribute('tabindex', '0');
183+
});
184+
});
185+
171186
test('should throw error if color is not a hex', () => {
172187
const component = () =>
173188
render(<EuiAvatar name="name" color="rgba(0,0,0,0)" />);

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from '../../services/color';
2323
import { toInitials, useEuiMemoizedStyles, useEuiTheme } from '../../services';
2424
import { IconType, EuiIcon, IconSize, IconColor } from '../icon';
25+
import { EuiToolTip } from '../tool_tip';
2526

2627
import { euiAvatarStyles } from './avatar.styles';
2728

@@ -201,29 +202,32 @@ export const EuiAvatar: FunctionComponent<EuiAvatarProps> = ({
201202
}, [iconColor, avatarStyle?.color, isForcedColors, euiTheme]);
202203

203204
return (
204-
<div
205-
css={cssStyles}
206-
className={classes}
207-
style={{ ...style, ...avatarStyle, ...highContrastBorder }}
208-
aria-label={isDisabled ? undefined : name}
209-
role={isDisabled ? 'presentation' : 'img'}
210-
title={name}
211-
{...rest}
212-
>
213-
{!imageUrl &&
214-
(iconType ? (
215-
<EuiIcon
216-
className="euiAvatar__icon"
217-
size={iconSize || size}
218-
type={iconType}
219-
color={iconCustomColor}
220-
/>
221-
) : (
222-
<span aria-hidden="true">
223-
{toInitials(name, initialsLength, initials)}
224-
</span>
225-
))}
226-
</div>
205+
<EuiToolTip content={name} disableScreenReaderOutput>
206+
<div
207+
css={cssStyles}
208+
className={classes}
209+
style={{ ...style, ...avatarStyle, ...highContrastBorder }}
210+
aria-label={isDisabled ? undefined : name}
211+
role={isDisabled ? 'presentation' : 'img'}
212+
tabIndex={0}
213+
{...rest}
214+
>
215+
{!imageUrl &&
216+
(iconType ? (
217+
<EuiIcon
218+
className="euiAvatar__icon"
219+
size={iconSize || size}
220+
type={iconType}
221+
color={iconCustomColor}
222+
aria-hidden={true}
223+
/>
224+
) : (
225+
<span aria-hidden="true">
226+
{toInitials(name, initialsLength, initials)}
227+
</span>
228+
))}
229+
</div>
230+
</EuiToolTip>
227231
);
228232
};
229233

0 commit comments

Comments
 (0)