Sub topic 15
Choosing among headless libraries
This chapter assumes you have read the earlier chapters on headless components, Radix primitives, and the shadcn/ui copy-and-own model. You should be comfortable with React hooks, context, and refs. The goal is to give you criteria for picking a headless library, so you can decide whether Radix is the right foundation for a given project.
What you are actually choosing
Every headless library ships behavior and accessibility without visual styles. They differ in four ways:
- API shape. Some give you compound components (
Dialog.Root,Dialog.Trigger). Some give you hooks that return props to spread onto your own elements. Some give you a small set of unstyled components that take aclassName. - Scope of behavior. Some stop at overlays and menus. Others also cover date pickers, drag and drop, comboboxes, and internationalization.
- Styling hooks. Libraries expose state in different ways:
data-stateattributes, render props, or class name functions. - Maintenance and ecosystem. This covers release cadence, who funds the project, and how many styled kits sit on top of it.
The table below summarizes common options. Verify details against each project's current documentation, because these libraries change quickly.
| Library | API shape | Notable strength | Styling hook |
|---|---|---|---|
| Radix UI Primitives | Compound components | The foundation shadcn/ui was built on, with a large ecosystem of examples | `data-state` and `data-disabled` attributes |
| React Aria Components | Components built on hooks | Very thorough accessibility, internationalization, date and time, drag and drop | `data-*` attributes plus render props and class name functions |
| React Aria (hooks) | Hooks | Maximum control over the rendered markup | You spread the returned props yourself |
| Headless UI | Components | Small API, made by the Tailwind CSS team | `data-*` attributes and render props |
| Ark UI | Components built on state machines | Works in React, Vue, and Solid | `data-*` attributes |
| Ariakit | Components and hooks | Strong composite widgets such as comboboxes and tabs | `data-*` attributes |
| Base UI | Components | Unstyled primitives from the team behind Material UI | `data-*` attributes and class name functions |
Recent versions of the shadcn/ui CLI can also generate components on top of Base UI as well as Radix. Check the current shadcn/ui documentation for the exact option, since this area is still changing. This is a useful reminder that the copied component layer and the headless layer can be separated.
The same dialog in two libraries
Here is the dialog from the Radix chapter again, followed by the same dialog written with React Aria Components. The behavior is equivalent: focus is trapped, Escape closes it, and the title labels it.
import * as Dialog from "@radix-ui/react-dialog"
export function RadixConfirm() {
return (
<Dialog.Root>
<Dialog.Trigger>Delete item</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay className="fixed inset-0 bg-black/50" />
<Dialog.Content className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-md bg-white p-6">
<Dialog.Title>Delete this item?</Dialog.Title>
<Dialog.Description>This action cannot be undone.</Dialog.Description>
<Dialog.Close>Cancel</Dialog.Close>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
)
}import {
Button,
Dialog,
DialogTrigger,
Heading,
Modal,
ModalOverlay,
} from "react-aria-components"
export function AriaConfirm() {
return (
<DialogTrigger>
<Button>Delete item</Button>
<ModalOverlay className="fixed inset-0 bg-black/50">
<Modal className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-md bg-white p-6">
<Dialog>
<Heading slot="title">Delete this item?</Heading>
<p>This action cannot be undone.</p>
<Button slot="close">Cancel</Button>
</Dialog>
</Modal>
</ModalOverlay>
</DialogTrigger>
)
}Three differences are worth noticing:
- React Aria Components uses its own
Buttonfor the trigger and the close control. Radix lets you put any element inTriggerandClose, andasChildswaps the rendered element. - React Aria splits the overlay, the modal container, and the dialog into three components. Radix combines positioning and content in
Dialog.Content. - The title is tied to the dialog through
slot="title"in React Aria. In Radix it is a dedicatedDialog.Titlecomponent.
Neither is better in general. They are two designs for the same contract, and your styling classes carry over almost unchanged.
Decision criteria
Work through these questions in order. Stop at the first one that decides the choice.
1. Does the library cover the widgets you need?
List the interactive widgets in your product before you compare anything else. A dashboard with dialogs, menus, and tabs fits almost any option. A scheduling app that needs a range calendar, time zones, and right-to-left support points toward React Aria, which has a large body of work on these areas. If one library lacks a widget, mixing two libraries is possible, but each one brings its own focus and layering behavior. Two dialog systems on one page can fight over focus traps and Escape handling.
2. Does it fit your framework and rendering model?
Check that the library supports your React version and server rendering. Components that use hooks need a "use client" directive in frameworks that split server and client components, such as Next.js. If you may leave React, Ark UI's multi-framework support has real value. If you are staying on React, it has little.
3. How much control do you need over markup?
Compound components such as Radix keep you close to the DOM and give you a fast start. Hook-based APIs, such as React Aria's hooks, let you build unusual structures, but you write more code and take on more responsibility for correct markup. Pick the least flexible API that does the job.
4. How does it handle state and styling?
A good headless library exposes component state to CSS. In Tailwind, that means variants such as data-[state=open]: on Radix or data-[pressed]: on React Aria Components. If a library only offers render props, you will use more conditional class logic with cn. Both work, but the first is easier to read in a class list.
5. Is the project healthy?
Check the release history, the open issue count, and who maintains it. Libraries do get retired. Reach UI, for example, is no longer actively developed, and many projects moved on. A library backed by a company with a product built on it, or by a large community, is less likely to stall. This matters more for headless code than for ordinary dependencies, because it sits under every interactive control you ship.
Keep the choice reversible
The copy-and-own model helps you here. Application code should import Button, Dialog, and Select from your own components/ui folder and never from the headless library directly. That makes the library an implementation detail of a few files.
// components/ui/confirm-dialog.tsx
// Application code imports ConfirmDialog from here.
// Only this file knows which headless library is underneath.
import * as React from "react"
import * as Dialog from "@radix-ui/react-dialog"
type ConfirmDialogProps = {
triggerLabel: string
title: string
description: string
children?: React.ReactNode
}
export function ConfirmDialog({ triggerLabel, title, description, children }: ConfirmDialogProps) {
return (
<Dialog.Root>
<Dialog.Trigger>{triggerLabel}</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay className="fixed inset-0 bg-black/50" />
<Dialog.Content className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-md bg-white p-6">
<Dialog.Title>{title}</Dialog.Title>
<Dialog.Description>{description}</Dialog.Description>
{children}
<Dialog.Close>Cancel</Dialog.Close>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
)
}If you later move this component to React Aria Components, the props of ConfirmDialog stay the same and callers do not change. The wrapper should expose a small, task-focused API, not mirror every Radix prop. A wrapper that passes through everything leaks the library back into your application.
Common mistakes
- Choosing by popularity alone. A large ecosystem helps, but the widget coverage and API shape in your product matter more.
- Mixing libraries for one widget family. Using Radix for the dialog and another library for the popover can cause conflicts in layering and outside-click handling. Test combinations that overlap.
- Assuming "headless" means "accessible by default". The library handles roles, focus, and keyboard behavior only for the parts you render through it. Your markup around it can still break labels, contrast, or reading order. The testing chapter covers how to check this.
- Migrating without a behavior checklist. Before swapping libraries, write down the keyboard and focus behavior you expect, such as focus returning to the trigger on close. Then verify it after the swap.
Summary
Radix is a strong default when you use shadcn/ui, because the CLI templates, documentation, and community examples all assume it. React Aria Components is a strong choice when you need deep internationalization or advanced widgets. Headless UI suits small Tailwind projects with a modest widget list. Ark UI matters when you share a design system across frameworks. Whatever you pick, put it behind your own components/ui layer.
Exercise
Your team is building a booking app that needs a date range picker, supports Arabic and English with right-to-left layout, and uses shadcn/ui for everything else. Which headless library would you evaluate for the date picker, why, and how would you keep the rest of the code from depending on that choice?
Show answer
Evaluate React Aria Components (or its hooks), because it covers range calendars, time zones, and internationalization including right-to-left layouts, which many other headless libraries do not cover. Build the date picker as a component inside components/ui with a small props API (for example value, onChange, minDate), and import it from there across the app. Test it next to the Radix-based dialogs and popovers to confirm that focus traps and Escape handling do not conflict. If you later change libraries, only that one file changes.