shadcn/ui and Radix primitives
These components are not a dependency. The generator copied source into the repository, and from
that moment it is ordinary project code that nobody upstream will patch for you.
When this fires
Adding, customizing or debugging a shadcn/ui component in a project that has components.json and
a vendored UI directory. It does not fire for choosing a component library, for a project using a
conventional installed component package, or for a full accessibility audit.
Procedure
- Confirm the model before assuming it.
components.json, a UI directory of component source,
and @radix-ui/* entries in package.json together mean copy-in. Read components.json for
the path aliases and conventions the generator will use — it decides where files land.
- Check whether the component already exists in the repo before adding it. Re-running the
generator for a component that is already there overwrites the file, including every local
change. If the file exists and has been customized, adding it again is destructive — stop and
ask rather than regenerating over someone's work.
- Add via the project's own generator invocation. Take the exact command from the project's
README or scripts; the CLI's package name and flags have changed across versions, so do not
type one from memory. If the generator cannot be run here, copy the upstream component source
into the same directory by hand and add the Radix dependency it imports — do not hand-roll a
substitute primitive, and do not silently skip the dependency.
- Customize in place. That is the model, not a workaround. Editing the vendored file is the
intended way to change these components. Prefer the two low-damage forms: add a variant to the
component's existing variant definition, and change appearance through the theme tokens rather
than by rewriting markup (see
tailwind).
- Wrap instead of edit when the change is product-specific. A project-specific composition
(your form field, your confirm dialog) belongs in a wrapper around the primitive, leaving the
vendored file close to upstream and re-addable. Deep edits to the vendored file are fine, but
they are the file you can no longer regenerate cheaply.
- Record which vendored files carry local edits. A comment at the top of the file, or a line
in the project's own notes — whichever the project already does. Without it, the next person
regenerates and loses the change silently.
- Keep the component's class-merge path intact. These components merge an incoming
className
with their own classes through a merge helper; if you rewrite that, caller overrides stop
working in ways that look like a styling bug.
- Use
asChild correctly when composing triggers. It renders the primitive's behaviour onto
your child element instead of its own: the child must be a single element that forwards props
and ref. A fragment, two children, or a component that drops props produces a control that looks
right and does nothing.
- Know what Radix gives you and what it does not. Free from the primitive: keyboard
interaction and focus management for the pattern, focus trapping and restoration in overlays,
dismissal behaviour, correct roles and state attributes, and the internal wiring between a
trigger and its content. Not free: an accessible name for an icon-only trigger, a label
associated with your own input, error text wired to the field it describes, colour contrast,
heading order, honouring reduced-motion, and a visible focus indicator if you removed the ring.
Those are yours every time.
- Verify with the keyboard and the accessibility tree, not a screenshot — tab to the control,
operate it, Escape out of it, and check the name it exposes. Rendered verification is
browser-verification.
Checklist
Failure handling
- A caller's
className does nothing — the merge helper was bypassed or the class conflicts
with the component's own. Fix the merge, not with !important.
- A trigger renders but does not open — suspect
asChild with a child that swallows props or
ref, or two children where one is required.
- The component switches between controlled and uncontrolled — a value prop that starts
undefined and later becomes defined. Pick one mode and keep it.
- "Upgrade shadcn" is asked for — there is no upgrade command for code you own. Diff the
current upstream source against each vendored file and apply changes deliberately, file by file,
keeping local edits. Say which files you did not touch.
- The generator is unavailable or offline — say so, copy the source manually or stop; do not
invent an approximation of a primitive and present it as the component.
- Accessibility looks handled because Radix is present — it is not a conclusion you can draw
from the import. The list in step 9 is checked by hand or reported as unchecked.
Evidence to report
Which components were added or edited and at what paths; whether each vendored file now carries
local changes; how customization was done (variant, token, wrapper, direct edit); the keyboard and
accessibility-tree checks you actually performed and what they showed; and anything from the
step-9 list you did not check.
1---2name: shadcn-ui3description: Work with shadcn/ui components and the Radix primitives under them — components are copied into the repo and are your source, so customize them in place, know that re-running the generator overwrites local edits, and know which accessibility behaviour Radix gives you and which it does not. Fires when adding, customizing or debugging a component in a repo with components.json and a vendored UI directory. Not for choosing a component library, not for general component structure, and not an accessibility audit.4---56# shadcn/ui and Radix primitives78These components are not a dependency. The generator copied source into the repository, and from9that moment it is ordinary project code that nobody upstream will patch for you.1011## When this fires1213Adding, customizing or debugging a shadcn/ui component in a project that has `components.json` and14a vendored UI directory. It does not fire for choosing a component library, for a project using a15conventional installed component package, or for a full accessibility audit.1617## Procedure18191. **Confirm the model before assuming it.** `components.json`, a UI directory of component source,20 and `@radix-ui/*` entries in `package.json` together mean copy-in. Read `components.json` for21 the path aliases and conventions the generator will use — it decides where files land.222. **Check whether the component already exists in the repo** before adding it. Re-running the23 generator for a component that is already there overwrites the file, including every local24 change. If the file exists and has been customized, adding it again is destructive — stop and25 ask rather than regenerating over someone's work.263. **Add via the project's own generator invocation.** Take the exact command from the project's27 README or scripts; the CLI's package name and flags have changed across versions, so do not28 type one from memory. If the generator cannot be run here, copy the upstream component source29 into the same directory by hand and add the Radix dependency it imports — do not hand-roll a30 substitute primitive, and do not silently skip the dependency.314. **Customize in place. That is the model, not a workaround.** Editing the vendored file is the32 intended way to change these components. Prefer the two low-damage forms: add a variant to the33 component's existing variant definition, and change appearance through the theme tokens rather34 than by rewriting markup (see `tailwind`).355. **Wrap instead of edit when the change is product-specific.** A project-specific composition36 (your form field, your confirm dialog) belongs in a wrapper around the primitive, leaving the37 vendored file close to upstream and re-addable. Deep edits to the vendored file are fine, but38 they are the file you can no longer regenerate cheaply.396. **Record which vendored files carry local edits.** A comment at the top of the file, or a line40 in the project's own notes — whichever the project already does. Without it, the next person41 regenerates and loses the change silently.427. **Keep the component's class-merge path intact.** These components merge an incoming `className`43 with their own classes through a merge helper; if you rewrite that, caller overrides stop44 working in ways that look like a styling bug.458. **Use `asChild` correctly when composing triggers.** It renders the primitive's behaviour onto46 your child element instead of its own: the child must be a single element that forwards props47 and ref. A fragment, two children, or a component that drops props produces a control that looks48 right and does nothing.499. **Know what Radix gives you and what it does not.** Free from the primitive: keyboard50 interaction and focus management for the pattern, focus trapping and restoration in overlays,51 dismissal behaviour, correct roles and state attributes, and the internal wiring between a52 trigger and its content. **Not** free: an accessible name for an icon-only trigger, a label53 associated with your own input, error text wired to the field it describes, colour contrast,54 heading order, honouring reduced-motion, and a visible focus indicator if you removed the ring.55 Those are yours every time.5610. **Verify with the keyboard and the accessibility tree**, not a screenshot — tab to the control,57 operate it, Escape out of it, and check the name it exposes. Rendered verification is58 `browser-verification`.5960## Checklist6162- [ ] `components.json` read; the component's target path known63- [ ] Existing file checked before any generator run, and overwrite consent obtained if needed64- [ ] Generator command taken from the project, not from memory65- [ ] Customization done in place, preferring variants and theme tokens66- [ ] Product-specific behaviour put in a wrapper, not baked into the primitive67- [ ] Local edits to vendored files recorded68- [ ] `className` merge path intact; caller overrides still apply69- [ ] Every `asChild` usage has exactly one prop-and-ref-forwarding child70- [ ] Icon-only controls have accessible names; inputs have associated labels71- [ ] Focus visible, keyboard path walked, Escape/dismiss checked7273## Failure handling7475- **A caller's `className` does nothing** — the merge helper was bypassed or the class conflicts76 with the component's own. Fix the merge, not with `!important`.77- **A trigger renders but does not open** — suspect `asChild` with a child that swallows props or78 ref, or two children where one is required.79- **The component switches between controlled and uncontrolled** — a value prop that starts80 `undefined` and later becomes defined. Pick one mode and keep it.81- **"Upgrade shadcn" is asked for** — there is no upgrade command for code you own. Diff the82 current upstream source against each vendored file and apply changes deliberately, file by file,83 keeping local edits. Say which files you did not touch.84- **The generator is unavailable or offline** — say so, copy the source manually or stop; do not85 invent an approximation of a primitive and present it as the component.86- **Accessibility looks handled because Radix is present** — it is not a conclusion you can draw87 from the import. The list in step 9 is checked by hand or reported as unchecked.8889## Evidence to report9091Which components were added or edited and at what paths; whether each vendored file now carries92local changes; how customization was done (variant, token, wrapper, direct edit); the keyboard and93accessibility-tree checks you actually performed and what they showed; and anything from the94step-9 list you did not check.