Repository navigation
Add a Tooltip to the Avatar in a Persona #32412
Replies: 2 comments 5 replies
|
Hi Mark Wu (@wfwf1997), in general it's only recommended to add tooltips to items that can be keyboard-focused. Otherwise, the tooltip content is inaccessible to keyboard and touch users. You may want to consider using one of the text slots of the Persona to add extra information instead. That said, one option to achieve what you're asking is to add a tooltip around the entire Persona, and then have it positioned above the Avatar, as shown in the Tooltip's Target story: https://react.fluentui.dev/?path=/docs/components-tooltip--docs#target Here's a stackblitz showing that: https://stackblitz.com/edit/b7edwo?file=src%2Fexample.tsx import * as React from 'react';
import { Persona, Tooltip } from '@fluentui/react-components';
export const PersonaWithTooltipExample = () => {
const [avatarRef, setAvatarRef] = React.useState<HTMLSpanElement | null>(
null
);
return (
<Tooltip
relationship="description"
content="The BOSS"
positioning={{ target: avatarRef }}
>
<Persona
name="Kevin Sturgis"
secondaryText="Available"
presence={{ status: 'available' }}
avatar={{
image: {
src: 'https://res-1.cdn.office.net/files/fabric-cdn-prod_20230815.002/office-ui-fabric-react-assets/persona-male.png',
},
ref: setAvatarRef,
}}
/>
</Tooltip>
);
}; |
|
Another option is to use a render function for the Here's a stackblitz showing that: https://stackblitz.com/edit/b7edwo-fhd4jz?file=src%2Fexample.tsx import * as React from 'react';
import {
Persona,
Tooltip,
Avatar,
AvatarProps,
} from '@fluentui/react-components';
export const PersonaWithTooltipExample = () => {
return (
<Persona
name="Kevin Sturgis"
secondaryText="Available"
presence={{ status: 'available' }}
avatar={{
image: {
src: 'https://res-1.cdn.office.net/files/fabric-cdn-prod_20230815.002/office-ui-fabric-react-assets/persona-male.png',
},
children: (AvatarSlot: typeof Avatar, props: AvatarProps) => (
<Tooltip relationship="description" content="The BOSS">
<AvatarSlot {...props} />
</Tooltip>
),
}}
/>
);
}; |

Another option is to use a render function for the
avatarslot. See the documentation for how to do that here: https://react.fluentui.dev/?path=/docs/concepts-developer-customizing-components-with-slots--docs#replacing-the-entire-slotHere's a stackblitz showing that: https://stackblitz.com/edit/b7edwo-fhd4jz?file=src%2Fexample.tsx