Hover Card Primitive
Allows users with vision to preview the content hidden behind an element before hovering or pressing.
Installation
Install the component via your command line.
Install @radix-ui/react-hover-card
Copy/paste the following code for web to ~/components/primitives/hover-card/hover-card.web.tsx
Copy/paste the following code for native to ~/components/primitives/hover-card/hover-card.tsx
Copy/paste the following code for types to ~/components/primitives/hover-card/types.ts
Copy/paste the following code for exporting to ~/components/primitives/hover-card/index.ts
Copy/paste the following code for native to ~/components/primitives/hover-card/index.tsx
Copy/paste the following code for types to ~/components/primitives/hover-card/types.ts
Usage
Props
Root
Extends View
props
Prop | Type | Note |
---|---|---|
onOpenChange | (value: boolean) => void | (optional) |
asChild | boolean | (optional) |
relativeTo | ’longPress’ | ‘trigger’ | Native Only_(optional)_ |
Trigger
Extends Pressable
props
Prop | Type | Note |
---|---|---|
asChild | boolean | (optional) |
TYPE: HoverCardTriggerRef
Methods | args | Note |
---|---|---|
open | opens the hover card | |
close | closes the hover card |
Portal
Prop | Type | Note |
---|---|---|
children* | React.ReactNode | |
forceMount | true | undefined | (optional) |
hostName | string | Web Only (optional) |
container | HTMLElement | null | undefined | Web Only (optional) |
Overlay
Extends Pressable
props
Prop | Type | Note |
---|---|---|
asChild | boolean | (optional) |
forceMount | true | undefined; | (optional) |
Content
Extends View
props
Prop | Type | Note |
---|---|---|
asChild | boolean | (optional) |
forceMount | true | undefined | (optional) |
alignOffset | number | (optional) |
insets | Insets | (optional) |
avoidCollisions | boolean | (optional) |
align | ’start’ | ‘center’ | ‘end’ | (optional) |
side | ’top’ | ‘bottom’ | (optional) |
sideOffset | number | (optional) |
disablePositioningStyle | boolean | Native Only (optional) |
collisionBoundary | Element | null | Array<Element | null> | Web Only (optional) |
sticky | ’partial’ | ‘always’ | Web Only (optional) |
hideWhenDetached | boolean | Web Only (optional) |
useRootContext
Must be used within a Root
component. It provides the following values from the dropdown menu: open
, and onOpenChange
.