---
name: shadcn
description: shadcn/ui components on Radix or Base UI.
title: shadcn
canonical_url: https://skilld.dev/gh/pymodel/react-frontend-skills/shadcn
last_updated: 2026-11-12T09:04:44.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> 44 supporting files sit beside this SKILL.md. When the Skill refers to one, fetch https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/PATH with PATH replaced.
>
> If the user asked to install this Skill, run `npx skilld install pymodel/react-frontend-skills/shadcn`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/shadcn`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/pymodel/react-frontend-skills/shadcn) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/shadcn`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/shadcn --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/shadcn --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# shadcn/ui Community Best Practices

Current best-practices guide for shadcn/ui applications. Before applying primitive-specific guidance, inspect whether the checked-in components use Radix UI or Base UI; current shadcn supports both (Base UI is the default for new projects) and their composition APIs differ. Component installs go through the CLI (v4), which resolves namespaced registries.

## When to Apply

Reference these guidelines when:
- Writing new shadcn/ui components or composing primitives
- Implementing forms with React Hook Form and Zod validation
- Building data tables or handling large dataset displays
- Customizing themes or adding dark mode support
- Reviewing code for accessibility compliance

## Rule Categories by Priority

| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Component Architecture | CRITICAL | `arch-` |
| 2 | Accessibility Preservation | CRITICAL | `ally-` |
| 3 | Styling & Theming | HIGH | `style-` |
| 4 | Form Patterns | HIGH | `form-` |
| 5 | Data Display | MEDIUM-HIGH | `data-` |
| 6 | Component Composition | MEDIUM | `comp-` |
| 7 | Performance Optimization | MEDIUM | `perf-` |
| 8 | State Management | LOW-MEDIUM | `state-` |

## Quick Reference

### 1. Component Architecture (CRITICAL)

- [`arch-use-asChild-for-custom-triggers`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/arch-use-asChild-for-custom-triggers.md) - Use the generated primitive's composition API
- [`arch-current-cli-registry`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/arch-current-cli-registry.md) - Use the current CLI for component lifecycle (v4, registries, MCP)
- [`arch-unified-radix-package`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/arch-unified-radix-package.md) - Import primitives from the unified radix-ui package
- [`arch-preserve-radix-primitive-structure`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/arch-preserve-radix-primitive-structure.md) - Maintain the generated compound component hierarchy
- [`arch-extend-variants-with-cva`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/arch-extend-variants-with-cva.md) - Use Class Variance Authority for type-safe variants
- [`arch-use-cn-for-class-merging`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/arch-use-cn-for-class-merging.md) - Use cn() utility for safe Tailwind class merging
- [`arch-forward-refs-for-composable-components`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/arch-forward-refs-for-composable-components.md) - Pass refs through for form and focus integration
- [`arch-isolate-component-variants`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/arch-isolate-component-variants.md) - Separate base styles from variant-specific styles

### 2. Accessibility Preservation (CRITICAL)

- [`ally-preserve-aria-attributes`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/ally-preserve-aria-attributes.md) - Keep the primitive's ARIA attributes intact
- [`ally-provide-sr-only-labels`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/ally-provide-sr-only-labels.md) - Add screen reader labels for icon buttons
- [`ally-maintain-focus-management`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/ally-maintain-focus-management.md) - Preserve focus trapping in modals
- [`ally-preserve-keyboard-navigation`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/ally-preserve-keyboard-navigation.md) - Keep WAI-ARIA keyboard patterns
- [`ally-ensure-color-contrast`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/ally-ensure-color-contrast.md) - Maintain WCAG color contrast ratios

### 3. Styling & Theming (HIGH)

- [`style-use-css-variables-for-theming`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/style-use-css-variables-for-theming.md) - Use CSS variables for theme colors
- [`style-avoid-important-overrides`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/style-avoid-important-overrides.md) - Prefer variants and class composition over important overrides
- [`style-use-tailwind-theme-extend`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/style-use-tailwind-theme-extend.md) - Define Tailwind v4 theme tokens in CSS
- [`style-consistent-spacing-scale`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/style-consistent-spacing-scale.md) - Use consistent Tailwind spacing scale
- [`style-responsive-design-patterns`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/style-responsive-design-patterns.md) - Apply mobile-first responsive design
- [`style-dark-mode-support`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/style-dark-mode-support.md) - Support dark mode with CSS variables

### 4. Form Patterns (HIGH)

- [`form-use-react-hook-form-integration`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/form-use-react-hook-form-integration.md) - Integrate with React Hook Form
- [`form-use-zod-for-schema-validation`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/form-use-zod-for-schema-validation.md) - Use Zod for type-safe validation
- [`form-show-validation-errors-correctly`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/form-show-validation-errors-correctly.md) - Show errors at appropriate times
- [`form-handle-async-validation`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/form-handle-async-validation.md) - Debounce async validation calls
- [`form-reset-form-state-correctly`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/form-reset-form-state-correctly.md) - Reset form state after submission

### 5. Data Display (MEDIUM-HIGH)

- [`data-use-tanstack-table-for-complex-tables`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/data-use-tanstack-table-for-complex-tables.md) - Use TanStack Table for sorting/filtering
- [`data-virtualize-large-lists`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/data-virtualize-large-lists.md) - Virtualize lists with 100+ items
- [`data-use-skeleton-loading-states`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/data-use-skeleton-loading-states.md) - Use Skeleton for loading states
- [`data-paginate-server-side`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/data-paginate-server-side.md) - Paginate large datasets server-side
- [`data-empty-states-with-guidance`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/data-empty-states-with-guidance.md) - Provide actionable empty states

### 6. Component Composition (MEDIUM)

- [`comp-compose-with-compound-components`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/comp-compose-with-compound-components.md) - Use compound component patterns
- [`comp-use-drawer-for-mobile-modals`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/comp-use-drawer-for-mobile-modals.md) - Use Drawer on mobile devices
- [`comp-combine-command-with-popover`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/comp-combine-command-with-popover.md) - Create searchable selects with Command
- [`comp-nest-dialogs-correctly`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/comp-nest-dialogs-correctly.md) - Manage nested dialog focus correctly
- [`comp-create-reusable-form-fields`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/comp-create-reusable-form-fields.md) - Extract reusable form field components
- [`comp-use-slot-pattern-for-flexibility`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/comp-use-slot-pattern-for-flexibility.md) - Use slot pattern for flexible content

### 7. Performance Optimization (MEDIUM)

- [`perf-lazy-load-heavy-components`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/perf-lazy-load-heavy-components.md) - Lazy load components over 50KB
- [`perf-memoize-expensive-renders`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/perf-memoize-expensive-renders.md) - Memoize list items and expensive components
- [`perf-optimize-icon-imports`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/perf-optimize-icon-imports.md) - Import icons through the package entry so the bundler can tree-shake them
- [`perf-avoid-unnecessary-rerenders-in-forms`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/perf-avoid-unnecessary-rerenders-in-forms.md) - Isolate form field watching
- [`perf-debounce-search-inputs`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/perf-debounce-search-inputs.md) - Debounce search and filter inputs

### 8. State Management (LOW-MEDIUM)

- [`state-prefer-uncontrolled-for-simple-inputs`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/state-prefer-uncontrolled-for-simple-inputs.md) - Use uncontrolled for simple forms
- [`state-lift-state-to-appropriate-level`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/state-lift-state-to-appropriate-level.md) - Lift state to lowest common ancestor
- [`state-use-controlled-dialog-state`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/state-use-controlled-dialog-state.md) - Control dialogs for programmatic access
- [`state-colocate-state-with-components`](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/shadcn/references/state-colocate-state-with-components.md) - Keep state close to where it's used

## How to Use

Run in the project root first:

```bash
npx -y @pymodel/react-frontend-skills detect  # installed vs. targeted versions
```

Read `references/<rule-id>.md` for each rule above that matches the task: why it matters, then incorrect vs. correct code.
