Skip to main content
The Slot component enables advanced component composition by merging props from a parent into its child element, allowing for flexible and reusable component patterns.

When to Use

  • Build polymorphic components with asChild patterns
  • Merge event handlers and props across component boundaries
  • Create flexible wrapper components that don’t add DOM nodes
  • Implement headless UI patterns
  • Compose ref forwarding across nested components

Basic Usage

Component API

Slot.Root

Merges all props into the first valid React element child.
React.ReactNode
required
Single React element to merge props into. Multiple children or non-elements will return null
React.Ref<HTMLElement>
Ref to forward. Will be composed with child’s ref if it exists
HTMLAttributes
Any props to merge into the child element (className, onClick, style, etc.)

Slot.Slottable

Marks content that should be preserved when using asChild pattern.
React.ReactNode
required
Content to preserve from the child element when slotting

Examples

Polymorphic Button Component

Merging Event Handlers

Complex Icon Button

Tooltip Trigger

Ref Forwarding

Dialog Trigger Pattern

Comparison to Native Patterns

Without Slot (Wrapper Element)

With Slot (Flexible Composition)

Common Use Cases

Design System Components

Accessible Disclosure

The Slot component automatically merges refs using composeRefs and props using mergeProps, ensuring event handlers and other props are properly combined.
Slot.Root requires exactly one valid React element child. Multiple children or text nodes will cause it to return null.

Implementation Details

  • Props are merged using mergeProps utility (className concatenation, event handler composition)
  • Refs are composed using composeRefs to support multiple ref assignments
  • Slot.Slottable marks content to preserve from the child when using asChild
  • Fragments are supported but their ref will not be forwarded