File: slot.md | Updated: 11/15/2025
ThemesThemes PrimitivesPrimitives IconsIcons ColorsColors
Documentation Case studies Blog
Search
/
Introduction Getting started Accessibility Releases
Styling Animation Composition Server-side rendering
Accordion
Alert Dialog
Aspect Ratio
Avatar
Checkbox
Collapsible
Context Menu
Dialog
Dropdown Menu
Form
Preview
Hover Card
Label
Menubar
Navigation Menu
One-Time Password Field
Preview
Password Toggle Field
Preview
Popover
Progress
Radio Group
Scroll Area
Select
Separator
Slider
Switch
Tabs
Toast
Toggle
Toggle Group
Toolbar
Tooltip
Accessible Icon Direction Provider Portal Slot Visually Hidden
Utilities
Merges its props onto its immediate child.
Can be used to support your own `asChild` prop.
Install the component from your command line.
npm install @radix-ui/react-slot
Import the component.
import { Slot } from "radix-ui";
export default () => (
<Slot.Root>
<div>Hello</div>
</Slot.Root>
);
Use to create your own asChild API.
When your component has a single children element:
// your-button.jsx
import * as React from "react";
import { Slot } from "radix-ui";
function Button({ asChild, ...props }) {
const Comp = asChild ? Slot.Root : "button";
return <Comp {...props} />;
}
Use Slottable when your component has multiple children to pass the props to the correct element:
// your-button.jsx
import * as React from "react";
import { Slot } from "radix-ui";
function Button({ asChild, children, leftElement, rightElement, ...props }) {
const Comp = asChild ? Slot.Root : "button";
return (
<Comp {...props}>
{leftElement}
<Slot.Slottable>{children}</Slot.Slottable>
{rightElement}
</Comp>
);
}
import { Button } from "./your-button";
export default () => (
<Button asChild>
<a href="/contact">Contact</a>
</Button>
);
Any prop that starts with on (e.g., onClick) is considered an event handler.
When merging event handlers, Slot will create a new function where the child handler takes precedence over the slot handler.
If one of the event handlers relies on event.defaultPrevented make sure that the order is correct.
import { Slot } from "radix-ui";
export default () => (
<Slot.Root
onClick={(event) => {
if (!event.defaultPrevented)
console.log("Not logged because default is prevented.");
}}
>
<button onClick={(event) => event.preventDefault()} />
</Slot.Root>
);
PreviousPortal
NextVisually Hidden