Radix UI unstyled accessible React components. Headless primitives. USE WHEN: user mentions "Radix", "Radix UI", "headless components", "unstyled primitives", asks about "accessible components", "Radix primitives" DO NOT USE FOR: shadcn/ui (use shadcn-ui skill), styled component libraries (Material-UI, Chakra), Vue/Svelte (use Headless UI)

GitHub
安装命令
npx skhub add claude-dev-suite/radix-ui
Markdown
SKILL.md

Radix UI - Quick Reference

When to Use This Skill

  • Accessible Dialog/Modal components
  • Dropdown menu, Select, Popover
  • Headless components to style with Tailwind

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: radix-ui for comprehensive documentation.

When NOT to Use This Skill

  • shadcn/ui project - Use shadcn-ui skill for pre-styled components
  • Need styled components - Use Material-UI, Chakra UI, Ant Design
  • Vue/Svelte projects - Use Headless UI or framework-specific libraries
  • Simple use cases - Native HTML elements might suffice

Essential Patterns

Dialog (Modal)

import * as Dialog from '@radix-ui/react-dialog';

<Dialog.Root>
  <Dialog.Trigger asChild>
    <button>Open</button>
  </Dialog.Trigger>
  <Dialog.Portal>
    <Dialog.Overlay className="fixed inset-0 bg-black/50" />
    <Dialog.Content className="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded">
      <Dialog.Title>Title</Dialog.Title>
      <Dialog.Description>Description</Dialog.Description>
      <Dialog.Close asChild>
        <button>Close</button>
      </Dialog.Close>
    </Dialog.Content>
  </Dialog.Portal>
</Dialog.Root>

Dropdown Menu

import * as DropdownMenu from '@radix-ui/react-dropdown-menu';

<DropdownMenu.Root>
  <DropdownMenu.Trigger asChild>
    <button>Menu</button>
  </DropdownMenu.Trigger>
  <DropdownMenu.Portal>
    <DropdownMenu.Content className="bg-white shadow-lg rounded p-2">
      <DropdownMenu.Item onSelect={() => handleEdit()}>
        Edit
      </DropdownMenu.Item>
      <DropdownMenu.Item onSelect={() => handleDelete()}>
        Delete
      </DropdownMenu.Item>
    </DropdownMenu.Content>
  </DropdownMenu.Portal>
</DropdownMenu.Root>

Select

import * as Select from '@radix-ui/react-select';

<Select.Root value={value} onValueChange={setValue}>
  <Select.Trigger className="select-trigger">
    <Select.Value placeholder="Select..." />
  </Select.Trigger>
  <Select.Portal>
    <Select.Content>
      <Select.Viewport>
        <Select.Item value="admin">
          <Select.ItemText>Admin</Select.ItemText>
        </Select.Item>
      </Select.Viewport>
    </Select.Content>
  </Select.Portal>
</Select.Root>

Controlled State

const [open, setOpen] = useState(false);
<Dialog.Root open={open} onOpenChange={setOpen}>

Common Props

PropUsage
asChildMerge props to child
open/onOpenChangeControlled state
side/alignPositioning
sideOffsetDistance offset

Anti-Patterns to Avoid

  • Do not forget Portal for z-index
  • Do not forget asChild to avoid wrapper divs
  • Do not neglect accessibility (ARIA labels)

Anti-Patterns

Anti-PatternWhy It's BadCorrect Approach
No Portal for overlaysZ-index issuesAlways use Portal for dialogs/dropdowns
Missing asChildExtra wrapper divsUse asChild to merge props
No controlled stateCan't track open/closeUse open/onOpenChange
Missing aria labelsNot accessibleAdd proper labels to all interactive elements
Inline styles onlyHard to maintainUse Tailwind classes or CSS modules
Not handling keyboard navPoor UXRadix handles it, don't override

Quick Troubleshooting

IssueCauseSolution
Overlay behind other elementsNo PortalWrap in Portal component
Extra div wrapperNot using asChildAdd asChild prop to Trigger/Content
Component not openingNo state managementAdd open/onOpenChange props
Styling not applyingWrong elementCheck Radix docs for data-attributes
Keyboard nav brokenPreventing defaultDon't preventDefault on Radix events
Type errorsWrong component importCheck @radix-ui/react-[component] package

Further Reading

For complete API reference: Radix UI Docs

发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

2026年9月24日

分类

未分类

许可证

MIT

源路径

skills/styling/radix-ui

默认分支

main

最新提交

9496306

Tree SHA

fe4e2f1