Sub topic 15
Choosing among headless libraries
This chapter assumes you have read the earlier chapters on headless components and Radix UI primitives. You should be comfortable with React components, TypeScript, and Tailwind classes.
Why the choice matters
shadcn/ui uses Radix UI for behavior, but Radix is not the only option. Other headless libraries solve the same problem: focus handling, keyboard support, and ARIA attributes, with no visual styling. Each differs in API shape, component coverage, and how much it leaves to you.
You will make this choice when a component you need is missing, or when you start a project outside the shadcn/ui ecosystem.
The main options
| Library | Style of API | Notable strength |
|---|---|---|
| Radix UI | Composable parts such as `Root`, `Trigger`, `Content` | Fits shadcn/ui directly and has wide coverage |
| React Aria Components | Components built on hooks, with state-based styling | Deep accessibility and internationalization work |
| Headless UI | Small set of components | Made by the Tailwind CSS team, so it pairs well with Tailwind |
| Base UI | Composable parts, similar to Radix | Newer library from the MUI team and former Radix authors |
| Ark UI | State-machine driven, available for several frameworks | Works outside React |
Check each library's current documentation before committing. Component lists and APIs change between releases.
The same dialog in React Aria Components
Compare this with the Radix dialog from earlier. The behavior is the same: a trigger, a modal layer, and a labelled dialog. The part names and the way you close the dialog differ.
import {
Button,
Dialog,
DialogTrigger,
Heading,
Modal,
} from "react-aria-components"
export function ConfirmDialog() {
return (
<DialogTrigger>
<Button>Delete item</Button>
<Modal>
<Dialog>
{({ close }) => (
<>
<Heading slot="title">Delete this item?</Heading>
<p>This action cannot be undone.</p>
<Button onPress={close}>Cancel</Button>
</>
)}
</Dialog>
</Modal>
</DialogTrigger>
)
}Notice onPress instead of onClick. React Aria normalizes mouse, touch, and keyboard input into one press event.
Decision criteria
Ask these questions in order:
- Does the component exist in your current library? If Radix already provides it, stay with it. Mixing libraries adds weight and inconsistent behavior.
- Does it need to match shadcn/ui conventions? Radix and Base UI use the same composable-parts shape, so your
cnandcvapatterns carry over unchanged. - Do you have special accessibility needs? Date pickers, complex comboboxes, and right-to-left or multi-locale support are where React Aria is strongest.
- Which framework do you target? If it is not React, a framework-agnostic library such as Ark UI narrows the field.
- How much maintenance can you absorb? A library with active releases and a clear changelog is safer than one that looks abandoned.
Common errors
- Mixing two libraries for the same pattern. Two dialog implementations in one app can trap focus differently and confuse keyboard users.
- Assuming styling carries over. Radix exposes
data-stateattributes, while React Aria uses its own state attributes such asdata-pressedanddata-focused. Your Tailwind variants must change with it. - Choosing by popularity alone. Verify keyboard behavior in your own browser and with a screen reader, as covered in the previous chapter.
Exercise
Your app uses shadcn/ui, and you need a date range picker that works in several locales. Radix has no such component. Which criterion from this chapter applies most, and what is a safe way to add the library?
Show answer
The special accessibility and internationalization needs criterion applies, which points to React Aria Components. Add it for this one component only. Wrap it in your own component file that uses cn and your theme variables, so the rest of the app keeps using Radix and the library can be swapped later.