Composition recipes

Practical patterns for combining Rad UI primitives into common product UI. Each recipe names who owns state and the minimum anatomy required for accessible behavior.

Confirm destructive action

Components: AlertDialog
State owner: parent (open / onOpenChange or uncontrolled trigger)

React
import AlertDialog from '@radui/ui/AlertDialog' export function DeleteAccountButton({ onConfirm }: { onConfirm: () => void }) { return ( <AlertDialog.Root> <AlertDialog.Trigger>Delete account</AlertDialog.Trigger> <AlertDialog.Content> <AlertDialog.Title>Delete account?</AlertDialog.Title> <AlertDialog.Description>This cannot be undone.</AlertDialog.Description> <AlertDialog.Cancel>Cancel</AlertDialog.Cancel> <AlertDialog.Action onClick={onConfirm}>Delete</AlertDialog.Action> </AlertDialog.Content> </AlertDialog.Root> ) }

Keep title and description in the content layer so screen readers announce purpose before action buttons.

Settings panel with sections

Components: Tabs + form controls
State owner: Tabs for active section; each field manages its own value

React
import Tabs from '@radui/ui/Tabs' import Switch from '@radui/ui/Switch' export function SettingsPanel() { return ( <Tabs.Root defaultValue="general"> <Tabs.List> <Tabs.Trigger value="general">General</Tabs.Trigger> <Tabs.Trigger value="notifications">Notifications</Tabs.Trigger> </Tabs.List> <Tabs.Content value="general">{/* general fields */}</Tabs.Content> <Tabs.Content value="notifications"> <Switch.Root> <Switch.Thumb /> </Switch.Root> </Tabs.Content> </Tabs.Root> ) }

Mount heavy panel content inside the active Tabs.Content only when panels are large.

Command palette

Components: Dialog + Command
State owner: dialog open; command value for selection

React
import Dialog from '@radui/ui/Dialog' import Command from '@radui/ui/Command' export function CommandMenu({ open, onOpenChange }: CommandMenuProps) { return ( <Dialog.Root open={open} onOpenChange={onOpenChange}> <Dialog.Content> <Command.Root> <Command.Input placeholder="Search…" /> <Command.List> <Command.Item onSelect={() => onOpenChange(false)}>Profile</Command.Item> </Command.List> </Command.Root> </Dialog.Content> </Dialog.Root> ) }

Trap focus inside the dialog; return focus to the opener when the palette closes.

Form field with label and error

Components: Field + TextArea (or any control)
State owner: Field (validation), or your form for server errors

React
import Field from '@radui/ui/Field' import TextArea from '@radui/ui/TextArea' export function DescriptionField({ error }: { error?: string }) { return ( <Field.Root name="description" required invalid={Boolean(error)}> <Field.Label>Description</Field.Label> <Field.Control asChild> <TextArea /> </Field.Control> <Field.Error>{error}</Field.Error> </Field.Root> ) }

Field links the label, help text and error to the control and sets aria-invalid, so there are no ids to wire by hand. See Forms & Validation.

One dialog for many rows

Components: Dialog with a handle
State owner: the handle (Dialog.createHandle())

React
import Dialog from '@radui/ui/Dialog' const deleteDialog = Dialog.createHandle<Invoice>() {invoices.map((invoice) => ( <Dialog.Trigger key={invoice.id} handle={deleteDialog} payload={invoice}>Delete</Dialog.Trigger> ))} <Dialog.Root handle={deleteDialog}> {({ payload }) => ( <Dialog.Portal> <Dialog.Content> <Dialog.Title>Delete {(payload as Invoice)?.number}?</Dialog.Title> <Dialog.Close>Cancel</Dialog.Close> </Dialog.Content> </Dialog.Portal> )} </Dialog.Root>

One Root serves every row, and focus returns to the row's button on close. Popover supports handles the same way and anchors to whichever trigger opened it.

Nested disclosure

Components: Accordion inside Card
State owner: Accordion (type, value, onValueChange)

Use accordion for FAQ-style content inside a card shell. Avoid nesting multiple roving-focus containers (menus inside accordion headers) without testing keyboard order.

asChild hands over semantics

asChild renders a part as your own element instead of its default one: a Trigger around your button component, a Field.Control on a TextArea. It's how you compose without the library anticipating every combination.

The trade-off: the part's behaviour and ARIA move onto your child. A Dialog.Trigger asChild makes your element the dialog's trigger (aria-haspopup, aria-expanded, click to open); a Button asChild around a <span> gives it role="button", focus and Enter/Space activation. Rad UI doesn't second-guess the element you pass, so check the result:

  • Use asChild to put a part's behaviour on an element that should have that role.
  • Don't use it to borrow a part's look for an element with a different role. A link that looks like a button should stay a link; Button asChild around an <a href> (or a router Link) keeps link semantics for exactly this reason.
  • When asChild changes the element type, check the accessibility tree or a screen reader.

Recipe checklist

  • Named which component owns open/selected/value state
  • Included required title/description parts for modal patterns
  • Verified keyboard and focus behavior manually
  • Used per-component imports (@radui/ui/Component)