Composition
Compose component parts around a single control so its styling, focus, and behavior stay together.
On this page
Compose a trigger with render
Use render on a part that exposes it, such as DialogTrigger or DialogClose. The rendered Button receives the props from the primitive and holds the focus. If you supply your own wrapper, pass the received props and ref through to its interactive DOM element.
Weekly report
Monday at 09:00 UTC
DialogTitle names the dialog and DialogDescription supplies its description. DialogContent includes the portal and backdrop. Find the parts and their options in the Dialog reference.
Style a link with asChild
Button asChild applies Button styling to one child element. An anchor retains its destination and link semantics. Give asChild a single element that accepts its props.
import { Button } from "@/components/ui/button"
export function ReportsLink() {
return (
<Button asChild variant="outline">
<a href="/components/button">View button reference</a>
</Button>
)
}Some primitive wrappers, including DialogTrigger, also accept asChild with a single element. Use the composition prop listed on the component you are working with.
Name the controls
- Use a label that names the action, such as “Edit report schedule”.
- Give icon-only controls an accessible name with
aria-label. - Test keyboard activation, dismissal with Escape, and focus returning to the dialog trigger after closing.