base-ui

Build accessible, composable UI with @base-ui/react primitives and project styling tokens. Use when creating or refining unstyled primitive components and behavior-heavy UI such as overlays, menus, po

SKILL.md

GitHub

Base UI Primitives - Skill

Name: base-ui Purpose: Build accessible, composable UI with @base-ui/react primitives and project styling tokens. Use this when creating or refining unstyled primitive components and behavior-heavy UI.

Applies when: Building overlays, menus, form controls, or custom component APIs with Base UI. Do not use when: You are using copied-in shadcn components as the primary implementation path (use moai-library-shadcn first).

Rules

  • Docs first: Start from reference-links.md, then read the exact component page before writing code.
  • Behavior before styling: Preserve Base UI interaction and accessibility behavior before adding project styles.
  • Styling agnostic: Keep logic and visuals decoupled; prefer wrappers and class composition over forking behavior code.
  • Composable APIs: Favor controlled/uncontrolled patterns, small props, and clear slots over monolithic components.
  • A11y is non-negotiable: Keep labels, descriptions, focus handling, keyboard support, and ARIA relationships intact.
  • Styled wrapper contracts: Preserve state-based className/style, render, refs, and cancelable events. Use packages/ui/lib/base-ui.ts to merge a Base UI class callback after receiving state; ordinary cn/CVA calls do not evaluate it.
  • Forms: Keep TanStack Form as the validation/submission owner. Base UI Field can supply accessible relationships without adding a second Form state system; the shared adapter is packages/ui/components/primitives/tanstack-form.tsx. Group labels name a group; they are not labels for Select/Combobox controls.
  • Shared ownership: Styled wrappers belong in packages/ui (components/shadcn or components/primitives), not in an app. Check for an existing @asym/ui component before adding one.

Workflow

  1. Check packages/ui/package.json for the installed @base-ui/react version and open the exact docs page from reference-links.md for the primitive you need.
  2. Implement behavior with Base UI primitives first, then layer project styles (cn, semantic tokens, Tailwind v4).
  3. Validate keyboard navigation, focus states, and screen-reader output.
  4. Run the checks relevant to the changed scope (typecheck, lint, unit, a11y).

Checklists

Implementation checklist

  • Primitive choice matches the interaction model (dialog/menu/select/etc.)
  • Controlled/uncontrolled behavior is explicit and testable
  • Styling is layered without breaking interaction semantics
  • Labels, descriptions, and focus behavior are preserved

Review checklist

  • No unnecessary re-implementation of behavior primitives
  • No prop explosion; component API stays composable
  • Keyboard-only interaction works end-to-end
  • Error/help text is correctly announced for form fields

Minimal examples

Wrapper-first composition

import { Field } from "@base-ui/react/field";

type FieldShellProps = {
  label: string;
  error?: string;
  children: React.ReactNode;
};

export function FieldShell({ label, error, children }: FieldShellProps) {
  return (
    <Field.Root invalid={Boolean(error)} className="grid gap-1.5">
      <Field.Label className="text-sm font-medium">{label}</Field.Label>
      {children}
      {error ? (
        <Field.Error match className="text-sm text-destructive">
          {error}
        </Field.Error>
      ) : null}
    </Field.Root>
  );
}

Use a Base UI-aware control such as the shared Input inside this shell. For product forms, reuse the TanStack adapter in packages/ui/components/primitives/tanstack-form.tsx instead of adding another field wrapper. The static shadcn Field layout parts also support display-only content and should not be globally replaced with behavioral Field.

Common mistakes / pitfalls

  • Styling first, then patching broken interactions later
  • Mixing multiple primitive systems in one component without intent
  • Building large wrapper components with too many boolean props