Color Picker Field
ColorPickerField is a Material UI TextField that shows a round color swatch and a read-only hex value, and opens a react-colorful HexColorPicker in a Popover when clicked. It is a controlled component that reports each new hex string through onChange.


shadcn add · no workarounds · theme neutral (none shipped)Installation
Requires @mui-treasury in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
import * as React from 'react';import { ColorPickerField } from '@/src/mui-treasury/components/color-picker-field';export function BrandColorInput() { const [color, setColor] = React.useState('#1976d2'); return ( <ColorPickerField label="Brand color" value={color} onChange={setColor} /> );}- Collecting a single hex color value inside a form, such as a theme, label, or tag color setting.
- Replacing a plain text input for hex codes where users benefit from a visual picker alongside the typed value.
- Building admin or settings screens that already use MUI TextField styling and need consistent field appearance.
- Avoid when you need alpha channels, HSL/RGB inputs, or a non-hex output format, since this item only uses HexColorPicker.
Examples
Controlled brand color field
Stores the selected hex string in React state and passes it back as value.
import * as React from 'react';import { ColorPickerField } from '@/src/mui-treasury/components/color-picker-field';export function BrandColorExample() { const [color, setColor] = React.useState('#1976d2'); return ( <ColorPickerField label="Brand color" value={color} onChange={setColor} fullWidth /> );}With helper text and size
Uses standard TextField props such as size, helperText, and variant, which are forwarded to the underlying TextField.
import * as React from 'react';import { ColorPickerField } from '@/src/mui-treasury/components/color-picker-field';export function TagColorExample() { const [color, setColor] = React.useState('#ff9800'); return ( <ColorPickerField label="Tag color" variant="filled" size="small" helperText="Used for tag background in the list view" value={color} onChange={setColor} /> );}Customizing input slot props
Passes slotProps.input to adjust the input element; sx is merged with the default pointer cursor on the input.
import * as React from 'react';import { ColorPickerField } from '@/src/mui-treasury/components/color-picker-field';export function ThemeColorExample() { const [color, setColor] = React.useState('#000000'); return ( <ColorPickerField label="Accent" value={color} onChange={setColor} slotProps={{ input: { sx: { fontFamily: 'monospace' }, }, }} /> );}API reference
Accessibility
- The swatch Box is marked aria-hidden, so screen readers rely on the input's value and label rather than the color fill.
- The input is readOnly, so users cannot type hex codes directly; the text is announced as the current value. Consider adding helperText or a visible label describing the field.
- Keyboard users cannot open the popover because the open trigger is a click handler on the TextField root; add keyboard activation (for example via a wrapper button) if keyboard access is required.
- HexColorPicker from react-colorful provides its own keyboard-operable saturation area and hue slider; verify focus order and labels in your app's context.
- Popover provides focus trapping and Escape-to-close by default, which is handled by MUI.
- Contrast of the hex text and swatch border depends on your theme; the border uses the theme divider color.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Color Picker Field" component (mui-treasury/color-picker-field) from its shadcn registry.1. Install it with: npx shadcn@latest add @mui-treasury/color-picker-field2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: value, onChange, slotProps, ref, ...TextFieldProps.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport * as React from 'react';import { ColorPickerField } from '@/src/mui-treasury/components/color-picker-field';export function BrandColorInput() { const [color, setColor] = React.useState('#1976d2'); return ( <ColorPickerField label="Brand color" value={color} onChange={setColor} /> );}```Files & dependencies
- components/color-picker-field/color-picker-field.tsx→ src/mui-treasury/components/color-picker-field/color-picker-field.tsx
- components/color-picker-field/index.ts→ src/mui-treasury/components/color-picker-field/index.ts