Agent Skillsudecode/plate › components

components

GitHub

提供React可访问性组件开发指南,涵盖语义HTML、键盘导航、ARIA属性及焦点管理,确保组件对残障用户可用。

.agents/skills/components/SKILL.md udecode/plate

Trigger Scenarios

创建或更新React组件 实现无障碍功能 修复可访问性问题

Install

npx skills add udecode/plate --skill components -g -y
More Options

Non-standard path

npx skills add https://github.com/udecode/plate/tree/main/.agents/skills/components -g -y

Use without installing

npx skills use udecode/plate@components

指定 Agent (Claude Code)

npx skills add udecode/plate --skill components -a claude-code -g -y

安装 repo 全部 skill

npx skills add udecode/plate --all -g -y

预览 repo 内 skill

npx skills add udecode/plate --list

SKILL.md

Frontmatter
{
    "name": "components",
    "metadata": {
        "skiller": {
            "source": ".agents\/rules\/components.mdc"
        }
    },
    "description": "React component architecture for creating composable, accessible components with data attributes. Use when creating\/updating composable components, not for higher-level feature\/page components."
}

Accessibility

URL: /accessibility

title: Accessibility description: Building components that are usable by everyone, including users with disabilities who rely on assistive technologies.

Accessibility (a11y) is not an optional feature—it's a fundamental requirement for modern web components. Every component must be usable by everyone, including people with visual, motor, auditory, or cognitive disabilities.

This guide is a non-exhaustive list of accessibility principles and patterns that you should follow when building components. It's not a comprehensive guide, but it should give you a sense of the types of issues you should be aware of.

If you use a linter with strong accessibility rules like Ultracite, these types of issues will likely be caught automatically, but it's still important to understand the principles.

Core Principles

  1. Semantic HTML First - Use native elements (<button>, <nav>, <ul>) for built-in accessibility
  2. Keyboard Navigation - Support Tab, Arrow keys, Home/End, Escape, Enter/Space for all interactions
  3. Screen Reader Support - Use ARIA attributes (aria-label, aria-current, aria-live) for proper announcements
  4. Visual Accessibility - Ensure focus indicators, sufficient contrast (4.5:1), and responsive text sizing

ARIA Patterns

ARIA enhances semantic HTML for assistive technologies. Key rules:

  1. Use semantic HTML first, ARIA only when necessary
  2. Don't override native semantics
  3. All interactive elements need keyboard access and accessible names

Common Attributes:

  • Roles - Define element type (role="button", role="navigation", role="alert")
  • States - Describe current state (aria-checked, aria-expanded, aria-selected)
  • Properties - Provide context (aria-label, aria-describedby, aria-controls, aria-required, aria-invalid)

Component Patterns

Complex interactive components require specific accessibility patterns. For detailed implementations, consult WAI-ARIA Authoring Practices.

Modal/Dialog:

  • role="dialog", aria-modal="true", aria-labelledby
  • Trap focus with Tab, close with Escape
  • Store and restore previous focus
  • Prevent body scroll when open

Dropdown Menu:

  • role="menu" on container, role="menuitem" on items
  • aria-haspopup="true", aria-expanded, aria-controls
  • Arrow keys navigate, Enter/Space select, Escape closes

Tabs:

  • role="tablist" on container, role="tab" on buttons, role="tabpanel" on panels
  • aria-selected, aria-controls, aria-labelledby
  • Arrow Left/Right navigate, Home/End jump to first/last
  • Only active tab is focusable (tabIndex={0/-1})

Forms:

  • <label htmlFor> paired with input id
  • aria-required, aria-invalid, aria-describedby for validation
  • Error messages with role="alert"
  • Group related inputs with <fieldset> and <legend>

Focus Management

  • Focus Visible - Use :focus-visible for keyboard-only focus indicators
  • Focus Trapping - Trap Tab/Shift+Tab within modals by cycling between first and last focusable elements
  • Focus Restoration - Store document.activeElement before opening overlays, restore on close

Live Regions

Announce dynamic content changes to screen readers:

  • Status Messages - aria-live="polite" (waits), aria-live="assertive" (interrupts), role="alert" for errors
  • Progress - role="progressbar" with aria-valuenow, aria-valuemin, aria-valuemax, aria-label

Color and Contrast

  • Contrast Ratios - Normal text: 4.5:1, Large text (≥18pt/14pt bold): 3:1, Non-text (icons, borders): 3:1
  • Color Independence - Never use color alone; combine with text, icons, or ARIA attributes

Mobile Accessibility

  • Touch Targets - Minimum 44×44px (iOS) or 48×48dp (Android)
  • Viewport - Allow zoom (<meta name="viewport" content="width=device-width, initial-scale=1">)

Common Pitfalls

  1. Placeholder as Label - Use persistent <label>, not disappearing placeholders
  2. Empty Buttons - Icon buttons need aria-label or visually hidden text
  3. Disabled Elements - Use aria-disabled instead of disabled to keep focusability and explain why

asChild

URL: /as-child

title: asChild description: How to use the asChild prop to render a custom element within the component.

The asChild prop is a powerful pattern in modern React component libraries. Popularized by Radix UI and adopted by shadcn/ui, this pattern allows you to replace default markup with custom elements while maintaining the component's functionality.

Understanding asChild

When asChild is true, instead of rendering its default DOM element, the component merges its props, behaviors, and event handlers with its immediate child element.

// Without asChild: Creates wrapper
<Dialog.Trigger><button>Open</button></Dialog.Trigger>
// Output: <button data-state="closed"><button>Open</button></button>

// With asChild: Merges props
<Dialog.Trigger asChild><button>Open</button></Dialog.Trigger>
// Output: <button data-state="closed">Open</button>

How It Works

Uses React.cloneElement to clone the child and merge props (including event handlers) from both parent and child components. The enhanced child is returned with combined functionality.

Key Benefits

  1. Semantic HTML - Use the most appropriate element (links for navigation, buttons for actions)
  2. Clean DOM Structure - Eliminates wrapper elements and "wrapper hell"
  3. Design System Integration - Works seamlessly with existing component libraries
  4. Component Composition - Compose multiple behaviors onto a single element

Common Use Cases

  • Custom Triggers - Replace default triggers with custom components or links
  • Accessible Navigation - Maintain semantic navigation elements
  • Form Integration - Integrate with form libraries while preserving functionality

Best Practices

  1. Maintain Accessibility - Ensure child elements have proper semantics and ARIA attributes
  2. Document Support - Use JSDoc to document the asChild prop in your component interfaces
  3. Test Forwarding - Verify props are properly forwarded to child components
  4. Handle Edge Cases - Consider conditional rendering and dynamic children

Common Pitfalls

  1. Not Spreading Props - Child components must spread ...props to receive merged behavior
  2. Multiple Children - asChild expects exactly one child element, not multiple
  3. Fragment Children - Fragments are not valid, use actual HTML elements

Composition

URL: /composition

title: Composition description: The foundation of building modern UI components.

Composition, or composability, is the foundation of building modern UI components. It is one of the most powerful techniques for creating flexible, reusable components that can handle complex requirements without sacrificing API clarity.

Instead of cramming all functionality into a single component with dozens of props, composition distributes responsibility across multiple cooperating components.

Fernando gave a great talk about this at React Universe Conf 2025, where he shared his approach to rebuilding Slack's Message Composer as a composable component.

Version History

  • af5e430 Current 2026-08-20 19:25

Same Skill Collection

.agents/skills/adversarial-document-reviewer/SKILL.md
.agents/skills/agent-browser-issue/SKILL.md
.agents/skills/agent-native-reviewer/SKILL.md
.agents/skills/architecture-strategist/SKILL.md
.agents/skills/autoclosure/SKILL.md
.agents/skills/autogoal/SKILL.md
.agents/skills/autoreview/SKILL.md
.agents/skills/best-practices-researcher/SKILL.md
.agents/skills/clawpatch/SKILL.md
.agents/skills/clawsweeper/SKILL.md
.agents/skills/code-simplicity-reviewer/SKILL.md
.agents/skills/coherence-reviewer/SKILL.md
.agents/skills/continue/SKILL.md
.agents/skills/correctness-reviewer/SKILL.md
.agents/skills/dev-browser/SKILL.md
.agents/skills/diagnosing-bugs/SKILL.md
.agents/skills/docs-creator/SKILL.md
.agents/skills/editor-harvest-plan/SKILL.md
.agents/skills/editor-test-harvester/SKILL.md
.agents/skills/feasibility-reviewer/SKILL.md
.agents/skills/framework-docs-researcher/SKILL.md
.agents/skills/frontend-design/SKILL.md
.agents/skills/git-history-analyzer/SKILL.md
.agents/skills/gpt-pro/SKILL.md
.agents/skills/grill-me/SKILL.md
.agents/skills/hard-cut/SKILL.md
.agents/skills/issue-intelligence-analyst/SKILL.md
.agents/skills/learnings-researcher/SKILL.md
.agents/skills/maintainability-reviewer/SKILL.md
.agents/skills/major-task/SKILL.md
.agents/skills/north-star/SKILL.md
.agents/skills/orchestrator/SKILL.md
.agents/skills/pattern-recognition-specialist/SKILL.md
.agents/skills/performance-oracle/SKILL.md
.agents/skills/performance/SKILL.md
.agents/skills/plate-plan/SKILL.md
.agents/skills/plate-plugin-creator/SKILL.md
.agents/skills/plate-ui/SKILL.md
.agents/skills/potion-yjs-dev-browser-test/SKILL.md
.agents/skills/product-lens-reviewer/SKILL.md
.agents/skills/project-standards-reviewer/SKILL.md
.agents/skills/promote-beta/SKILL.md
.agents/skills/react-useeffect/SKILL.md
.agents/skills/react/SKILL.md
.agents/skills/registry-changelog/SKILL.md
.agents/skills/release-lanes/SKILL.md
.agents/skills/repo-research-analyst/SKILL.md
.agents/skills/reproduce-bug/SKILL.md
.agents/skills/research-wiki/SKILL.md

Metadata

Files
0
Version
cce36d3
Hash
b7e2e0c1
Indexed
2026-08-20 19:25

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-16 13:41
浙ICP备14020137号-1 $mapa de visitantes$