import * as React from 'react'; import { HoverCard, IExpandingCardProps, DirectionalHint, DetailsList, buildColumns, IColumn, ThemeProvider, KeyCodes, mergeStyleSets, } from '@fluentui/react'; import { createListItems, IExampleItem } from '@fluentui/example-data'; import { useBoolean, useConst } from '@fluentui/react-hooks'; const classNames = mergeStyleSets({ compactCard: { display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', }, expandedCard: { padding: '16px 24px', }, item: { selectors: { '&:hover': { textDecoration: 'underline', cursor: 'pointer', }, }, }, }); const log = (text: string): (() => void) => { return (): void => { console.log(text); }; }; const items: IExampleItem[] = createListItems(10); const columns: IColumn[] = buildColumns(items).filter(column => column.name === 'location' || column.name === 'key'); const onRenderCompactCard = (item: IExampleItem): JSX.Element => { return (
{item.location}
); }; const onRenderExpandedCard = (item: IExampleItem): JSX.Element => { return (
{item.description}
); }; /** * Used for the hoverable "key" cell. In this case, the implementation uses hooks to control * open/closed state, so it must be a function component (not just code within a render callback). */ const KeyCellWithHoverCard: React.FunctionComponent<{ item: IExampleItem }> = ({ item }) => { const [contentRendered, { toggle: toggleContentRendered }] = useBoolean(false); const targetElementRef: React.RefObject = React.useRef(null); const expandingCardProps: IExpandingCardProps = useConst({ onRenderCompactCard, onRenderExpandedCard, renderData: item, directionalHint: DirectionalHint.rightTopEdge, gapSpace: 16, calloutProps: { isBeakVisible: true, }, }); React.useEffect(toggleContentRendered, [toggleContentRendered]); return (
{item.key} {contentRendered && ( )}
); }; const onRenderItemColumn = (item: IExampleItem, index: number, column: IColumn): JSX.Element | React.ReactText => { if (column.key === 'key') { return ; } return item[column.key as keyof IExampleItem]; }; export const HoverCardTargetExample: React.FunctionComponent = () => { return (

Hover over the key cell of a row item to see the card or use the keyboard to navigate to it by tabbing to a row and hitting the right arrow key.

When using the keyboard to navigate, open the card with the hotkey and it will automatically focus the first focusable element in the card allowing further navigation inside the card. The hotkey is defined by the{' '} openHotKey prop and is defined as 'enter' in the following example.

); };