Skip to content

components/floating/HoverCard

import { … } from 'zidane-ui'ui/src/components/floating/HoverCard.tsx

Popover (click)
HoverCard (hover)
Hover me
RowActionsMenu (3-dots)
Tooltip, inline and portaled

Components#

HoverCardComponent#

Renders a trigger and a card that opens while the trigger is hovered or focused. The card opens after 250 ms, so sweeping the pointer across a list opens nothing, and stays open while the pointer or focus is on it. It closes 150 ms after both leave, and Esc closes it at once.

TypeScript
function HoverCard(props: HoverCardProps): Element
Parameters
NameTypeDescription
propsHoverCardProps

Component props.

Element
HoverCard props
NameTypeDefaultDescription
align?Align'start'

How the card lines up along the trigger's edge.

anchorTo?(trigger: HTMLElement) => HTMLElement | null

Position against another element than the trigger (a sidebar badge's card against its whole row, so it opens beside the list instead of over the rows below). null: the trigger.

ariaLabelstring

Accessible name of the card, which has the dialog role.

childrenReactNode

The card's content.

side?Side'right'

Preferred side of the trigger. It flips when it does not fit.

testId?string

Test id for the card element.

trigger(props: HoverCardTriggerProps, open: boolean) => ReactNode

Renders the trigger. Spread the received props onto the element; open is whether the card is shown.

width?number

Fixed width of the card in px. Sized by its content when omitted.

ui/src/components/floating/HoverCard.tsx:72

Interfaces#

HoverCardPropsInterface#

Props for HoverCard.

TypeScript
interface HoverCardProps
HoverCardProps properties
NameTypeDefaultDescription
align?Align'start'

How the card lines up along the trigger's edge.

anchorTo?(trigger: HTMLElement) => HTMLElement | null

Position against another element than the trigger (a sidebar badge's card against its whole row, so it opens beside the list instead of over the rows below). null: the trigger.

ariaLabelstring

Accessible name of the card, which has the dialog role.

childrenReactNode

The card's content.

side?Side'right'

Preferred side of the trigger. It flips when it does not fit.

testId?string

Test id for the card element.

trigger(props: HoverCardTriggerProps, open: boolean) => ReactNode

Renders the trigger. Spread the received props onto the element; open is whether the card is shown.

width?number

Fixed width of the card in px. Sized by its content when omitted.

ui/src/components/floating/HoverCard.tsx:32

HoverCardTriggerPropsInterface#

Props HoverCard passes to its trigger function, to spread onto the trigger element.

TypeScript
interface HoverCardTriggerProps
HoverCardTriggerProps properties
NameTypeDescription
onBlur?(event: FocusEvent<HTMLElement>) => void

Starts the close delay when focus leaves the trigger, unless it moves into the card.

onFocus?() => void

Optional in the type so callers that build these props themselves still compile.

onPointerEnter() => void

Starts the open delay when the pointer enters the trigger.

onPointerLeave() => void

Starts the close delay when the pointer leaves the trigger.

ref(node: HTMLElement | null) => void

Ref callback that registers the trigger as the card's anchor.

ui/src/components/floating/HoverCard.tsx:18