AppColorField
A colour swatch beside a hex input, both editing one value.
<app-color-field label="Accent" name="Accent" value="#4F46E5" /><app-color-field> is for the handful of places a user picks a colour: a brand accent in settings, a tag colour, a chart series. The swatch opens the OS picker; the text box takes a pasted hex.
Both halves are there on purpose. A bare <input type="color"> cannot be typed into — a keyboard or screen-reader user, or anyone with a hex from a brand guide, would be stuck. The text box is the accessible path and the field that posts; the swatch is tabindex="-1" and unnamed.
Playground
Every attribute, live. Each change re-renders the real tag helper on the server, so the markup underneath is the exact call that produced the field above it.
Basic
A value and a name. Both controls edit the same colour.
Show code
<app-color-field label="Accent colour" name="Accent" value="#4F46E5" />
#4F4.Sizes
Three sizes, the same sm / md / lg contract as <app-input>. The swatch and hex box resize together. Default (md) suits almost everything; use sm inside dense settings rows, lg for a marketing-scale field.
Show code
<app-color-field label="Small" name="Accent" size="sm" … /> <app-color-field label="Medium" name="Accent" … /> <app-color-field label="Large" name="Accent" size="lg" … />
States
The same label / required / hint / error contract as every other field, so it drops into a form beside <app-input> without looking different.
Show code
<app-color-field label="Accent colour" name="Accent" required="true" … /> <app-color-field label="Accent colour" name="Accent" hint="Used for buttons and links." … /> <app-color-field label="Accent colour" name="Accent" error="Enter a 6-digit hex" … />
When to use
Use it when
- The user genuinely needs an arbitrary colour — a brand accent, a tag colour.
- A hex from a brand guide will be pasted in.
- The field sits in a settings or theming form.
Reach for something else when
- There is a fixed palette to choose from. → app-choice-chip / app-choice-card
- The colour carries meaning (status, severity). → app-status-badge
- It is any other single-line value. → app-input
Best practices
Every option
The whole surface of the component, one cell per value — including states a normal example never shows together.
size — every size
size="sm"
size="md"
size="lg"
state
(default)requiredhinterrorerror + hint (error wins)disabledrequired + errorvalue — complete vs incomplete hex
value="#4F46E5" — complete, swatch matchesvalue="#4F4" — incomplete, swatch falls back to #000000value="" — empty, swatch falls back to #000000no label
label omitted — swatch aria-label falls back to "Colour"Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| value | string | #000000 | Hex colour, e.g. #4F46E5. |
| label | string | — | Field label. |
| name | string | — | Field name on the text box — the control that posts. |
| id | string | auto-generated | Ties the label to the text box. Defaults to an auto-generated id (not name) — repeated rows sharing a name (e.g. inside AppRepeater) must not collide on id. |
| required | bool | false | Draws the asterisk and sets required on the text box. |
| error | string | — | Validation message; replaces the hint. |
| hint | string | — | Say what the colour affects. |
| disabled | bool | false | Disables both controls. |
| size | sm | md | lg | md | Control size. sm/lg resize the swatch and hex box together. |
| input-class | string | — | Extra classes on the control itself (the hex input) — the React className counterpart. The plain class attribute merges onto the .field wrapper instead. |