Slot
Merges its props onto its immediate child. This is a utility component used internally by other components to enable the asChild pattern.
Usage with asChild
The Slot component is the foundation of the asChild pattern used throughout Mantle. When a component supports asChild, it uses Slot internally to merge its props onto the child element instead of rendering a wrapper.
Class name merging
Slot automatically merges className props using Tailwind CSS's merge logic. Child classes take priority over parent classes for conflicting styles, while non-conflicting classes are preserved.
Render props on the child
Some components resolve their own className or style from state only they know: react-router's
NavLink calls className={({ isActive }) => …} with its own match state. Slot composes those: when the
child's className or style is a function, the merged value is a function of the same shape, which forwards
the child's own arguments to the child's function and merges the result at the same child-wins precedence.
That is what lets a router link keep its active styling through a mantle part's asChild:
Slot never calls the function itself: it cannot know the argument is { isActive, isPending, isTransitioning },
and it does not need to. NavLink calls it.
Reach for this to add styling of your own. You do not need it for the active row treatment a mantle part
already ships: Sidebar.ItemButton styles its current row from aria-current="page" as well as
data-current, and NavLink sets that attribute itself, so
<Sidebar.ItemButton asChild><NavLink to="…" /></Sidebar.ItemButton>
highlights with no className, no current, and no useMatch.
A function children is forwarded untouched, so NavLink's children={({ isActive }) => …} works too.
API Reference
Slot
Merges its props onto its immediate child element. Automatically handles className merging with Tailwind CSS merge logic.
Based on Radix UI Slot.