import * as React from 'react'; import { Toggle } from '@fluentui/react/lib/Toggle'; import { Label } from '@fluentui/react/lib/Label'; import { TooltipHost, TooltipOverflowMode, ITooltipHostStyles } from '@fluentui/react/lib/Tooltip'; import { mergeStyleSets, getTheme } from '@fluentui/react/lib/Styling'; import { css } from '@fluentui/react/lib/Utilities'; import { useId } from '@fluentui/react-hooks'; const contentParent = "If the parent element's content overflows, hovering here will show a tooltip (anchored to the parent element)."; const contentSelf = "If the TooltipHost's content overflows, hovering here will show a tooltip (anchored to the TooltipHost)."; // The TooltipHost uses display: inline by default, which causes issues with this example's // styling and layout. Use display: block instead. (other styles are just to look nice) const theme = getTheme(); const hostStyles: Partial = { root: { display: 'block', padding: 10, backgroundColor: theme.palette.themeLighter }, }; const classNames = mergeStyleSets({ // Applied to make content overflow (and tooltips activate) overflow: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', width: 200, }, // Just to look nice example: { marginTop: 20, selectors: { '> *:first-child': { paddingBottom: 10 } } }, parent: { padding: 10, border: '2px dashed ' + theme.palette.neutralTertiary, selectors: { '> *:last-child': { marginTop: 10 } }, }, }); export const TooltipOverflowExample: React.FunctionComponent = () => { const parentTooltipId = useId('text-tooltip'); const [shouldOverflow, setShouldOverflow] = React.useState(false); const [isParentTooltipVisible, setIsParentTooltipVisible] = React.useState(false); const onOverflowChange = React.useCallback(() => setShouldOverflow(!shouldOverflow), [shouldOverflow]); return (
{/* Example of TooltipOverflowMode.Parent */}
{/* This parent element will overflow */}
This is the parent element.
{/* Example of TooltipOverflowMode.Self */}
This is the TooltipHost area. {contentSelf}
); };