Sub topic 1
What Accessible Components Must Do
Prerequisites
Assume working knowledge of React function components, props, hooks, TypeScript, and basic Tailwind CSS. You should also be comfortable installing npm packages.
What Accessible Components Must Do
An accessible component communicates its purpose and state to different kinds of users. Prefer semantic HTML, such as <button> for actions and <nav> for navigation. Add an accessible name through visible text, a label, or an appropriate ARIA attribute when native HTML is not enough.
Interactive components must support keyboard use. Focus should move predictably, remain visible, and return to a sensible element when a temporary surface closes. A dialog, for example, should trap focus while open and close when the user presses Escape.
Screen readers also need state changes. Attributes such as aria-expanded, aria-selected, and aria-invalid expose state that visual styling alone cannot communicate.
Headless Components: Behavior Without Styles
A headless component provides behavior, state management, and accessibility without imposing visual design. You supply the markup and styles. This separation lets a design system keep its own colors, spacing, and layout while reusing tested interaction logic.
Styling with Tailwind Utilities
Tailwind CSS styles elements with small utility classes. For example, fixed inset-0 bg-black/50 creates a full-screen, translucent overlay. Utilities keep styles close to component structure, but long conditional class lists need an organized composition strategy.
Radix UI Primitives in Practice
Radix UI provides headless React primitives for patterns such as dialogs, menus, and popovers. The primitive manages interaction details, while your classes control appearance.
import * as Dialog from "@radix-ui/react-dialog"
export function ConfirmDialog() {
return (
<Dialog.Root>
<Dialog.Trigger className="rounded bg-blue-600 px-4 py-2 text-white">
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 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>
)
}How shadcn/ui Works: Copy, Own, and Modify
A conventional component library remains an installed dependency. shadcn/ui instead uses a CLI to copy component source into your project. You own that source and can change it directly. Its components commonly combine Tailwind classes with Radix primitives and utilities such as cn.
npx shadcn@latest init
npx shadcn@latest add button dialogThis model gives you control, but updates are your responsibility. Keep local changes intentional and compare upstream changes before copying an update.
Exercise
Why might a team choose shadcn/ui instead of importing a component library?
Show answer
The team owns the copied source, so it can customize behavior and styling without waiting for a library release.