compound-components

Build accessible React UI primitives with compound component patterns.

38|3|Updated Dec 29, 2025
One-click install
npx skills add https://github.com/dylantarre/design-system-skills --skill compound-components
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compound-components
Source: https://github.com/dylantarre/design-system-skills/tree/main/skills/patterns/compound-components
Command: npx skills add https://github.com/dylantarre/design-system-skills --skill compound-components

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps teams build accessible, composable UI primitives that manage complex interaction patterns (open state, focus, keyboard, ARIA) without duplicating logic across components.

Core Features & Use Cases

  • Root/Trigger/Content/Item architecture with context sharing
  • ARIA roles and data-state attributes for accessibility
  • Keyboard navigation: Arrow keys, Enter/Space, Escape
  • Focus management and accessibility best practices
  • Use case: building a design-system library with Select, Dialog, Tabs, Accordion, and Menu

Quick Start

Outline the steps to implement compound components in your React app:

  1. Define the main parts: Root, Trigger, Content, Item.
  2. Create a Root with unified state, IDs, and context.
  3. Implement Trigger and Content to read context and toggle open state.
  4. Add keyboard navigation and focus management.
  5. Validate with keyboard-only navigation and screen readers.

Frequently Asked Questions about compound-components

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build accessible React UI components with the compound component pattern?

Build accessible React UI components using a Root/Trigger/Content/Item architecture with shared context, ARIA roles, and keyboard navigation to manage complex interaction patterns without duplicating logic. This approach ensures predictable behavior across libraries.

What is the compound component pattern and when do I need it for a design system?

The compound component pattern is a React architecture using Root, Trigger, Content, and Item parts to share state via context. Use it when building design-system primitives like Select, Dialog, Tabs, Accordion, and Menu to ensure flexible rendering and accessibility.

How do I add keyboard navigation and focus management to React accordions and menus?

Add keyboard navigation and focus management to React accordions and menus by implementing Arrow keys, Enter/Space, and Escape handling within a compound component context. This ensures proper focus trapping and screen reader compatibility for interactive UI primitives.

Does the compound component pattern work with headless UI libraries like Radix UI?

Yes, the compound component pattern works with headless UI libraries like Radix UI. It applies the same Root/Trigger/Content structure, ARIA roles, and data-state attributes to enable flexible rendering and predictable behavior across different library implementations.

Can I use compound components to manage open state and ARIA attributes without duplicating logic?

Yes, you can use compound components to manage open state, IDs, and ARIA attributes without duplicating logic. A Root component holds unified state and shares it via context, allowing Trigger and Content parts to read and toggle state predictably.

Why use compound components instead of single monolithic React components for dialogs and selects?

Use compound components instead of single monolithic React components to achieve flexible rendering and predictable behavior. This pattern separates Root, Trigger, and Content parts via context, preventing logic duplication when building accessible dialogs, selects, and menus.