Color Picker
A saturation/value canvas, hue and alpha tracks, a hex field and preset swatches, all driving one HSVA model projected to a color string.
Value:
<NaviusColorPicker @bind-Value="_color" Format="hex" class="w-60 space-y-3">
<NaviusColorPickerArea class="h-32 w-full rounded-md" />
<NaviusColorPickerHueSlider class="h-3 w-full rounded-full" />
<div class="flex items-center gap-2">
<NaviusColorPickerSwatch class="h-9 w-9 rounded-md border" />
<NaviusColorPickerField class="h-9 w-full rounded-md border px-2 uppercase" />
</div>
</NaviusColorPicker>
@code { private string? _color = "#4F46E5"; }Features
- The root owns the color as HSVA and projects it to
ValuethroughFormat(hex/rgb/rgba/hsl/hsla). - The Area is a 2D slider (two grouped
role="slider"thumbs, one per channel); the Hue and Alpha tracks each drive one channel. Every track is keyboard-drivable. - The Field commits a typed hex / rgb / hsl string; the Swatches are an APG listbox of presets. All surfaces write back to the same model.
- Controlled via
@bind-Value, uncontrolled viaDefaultValue; a hidden input mirrors the projected string into form submission whenNameis set.
Installation
Install the brain, or copy just this primitive in with the CLI.
navius add color-pickerAnatomy
Import the parts and compose only the ones you need. The Area's hue-fill and the track gradients are rendered inline (they are intrinsic to each control).
@using Navius.Primitives.Components.ColorPicker
<NaviusColorPicker>
<NaviusColorPickerArea />
<NaviusColorPickerHueSlider />
<NaviusColorPickerAlphaSlider /> @* only with AlphaEnabled *@
<NaviusColorPickerSwatch />
<NaviusColorPickerField />
<NaviusColorPickerSwatches Colors="_presets">
@* or explicit <NaviusColorPickerSwatchItem Value="#f00" /> children *@
</NaviusColorPickerSwatches>
</NaviusColorPicker>API Reference
Root
NaviusColorPicker. Owns the HSVA color and projects it to Value. Renders a div. Value is two-way bindable.
| Prop | Type | Default |
|---|---|---|
| Value | string? | - |
| ValueChanged | EventCallback<string> | - |
| DefaultValue | string? | - |
| Format | string | "hex" |
| AlphaEnabled | bool | false |
| Disabled | bool | false |
| ReadOnly | bool | false |
| Name | string? | - |
| ChildContent | RenderFragment? | - |
| …attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-navius-color-picker] | Present on the root |
| [data-disabled] | Present when disabled |
Area
NaviusColorPickerArea. The 2D saturation/value canvas: a role=group with a visible saturation slider and a visually-hidden brightness slider. Renders a div.
| Prop | Type | Default |
|---|---|---|
| AriaLabel | string? | "Color" |
| …attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-navius-color-picker-area] | Present on the canvas group |
| [data-navius-color-picker-area-thumb] | The visible saturation (x) thumb |
| [data-navius-color-picker-area-thumb-y] | The visually-hidden brightness (y) slider |
| [data-channel] | "saturation" | "brightness" |
| [data-dragging] | Present on a thumb while dragging |
| [data-disabled] | Present when disabled |
HueSlider
NaviusColorPickerHueSlider. The horizontal rainbow track with a role=slider thumb. Renders a div.
| Prop | Type | Default |
|---|---|---|
| …attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-navius-color-picker-hue] | Present on the hue track |
| [data-navius-color-picker-hue-thumb] | The hue slider thumb |
| [data-orientation] | "horizontal" |
| [data-dragging] | Present on the thumb while dragging |
AlphaSlider
NaviusColorPickerAlphaSlider. The optional opacity track (transparent to opaque over a checkerboard). Only meaningful with AlphaEnabled. Renders a div.
| Prop | Type | Default |
|---|---|---|
| …attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-navius-color-picker-alpha] | Present on the alpha track |
| [data-navius-color-picker-alpha-thumb] | The alpha slider thumb |
| [data-orientation] | "horizontal" |
| [data-dragging] | Present on the thumb while dragging |
Field
NaviusColorPickerField. A text field that commits a typed hex / rgb / hsl on change; a bad value flips data-invalid without disturbing the color. Renders an input.
| Prop | Type | Default |
|---|---|---|
| AriaLabel | string? | "Hex color" |
| …attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-navius-color-picker-field] | Present on the input |
| [data-invalid] | Present when the typed value did not parse |
Swatch
NaviusColorPickerSwatch. A non-interactive preview of the current color (the color is its accessible name). Renders a div with role=img.
| Prop | Type | Default |
|---|---|---|
| …attributes | IDictionary<string, object>? | - |
Swatches
NaviusColorPickerSwatches. A preset grid (APG listbox); auto-renders SwatchItems from Colors, or takes explicit children. Renders a div with role=listbox.
| Prop | Type | Default |
|---|---|---|
| AriaLabel | string? | "Swatches" |
| Colors | IReadOnlyList<string>? | - |
| ChildContent | RenderFragment? | - |
| …attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-navius-color-picker-swatches] | Present on the listbox |
SwatchItem
NaviusColorPickerSwatchItem. One preset (role=option); click / Space / Enter applies it. Renders a button.
| Prop | Type | Default |
|---|---|---|
| Value | string | "" |
| ChildContent | RenderFragment? | - |
| …attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-navius-color-picker-swatch-item] | Present on the option button |
| [data-selected] | Present when it matches the current color |
| [data-disabled] | Present when disabled |
Accessibility
The Area follows react-aria's ColorArea: a role="group" of two role="slider" thumbs, each exposing its own aria-valuenow, with aria-valuetext announcing the resulting color. The Hue and Alpha tracks are single sliders. The Swatches are an role="listbox" with a roving tabindex.
Keyboard interactions
| Key | Description |
|---|---|
| Arrow keys (Area) | Left/Right adjust saturation, Up/Down adjust brightness (Shift takes a larger step). |
| Home / End (Area) | Jumps saturation to its extremes. |
| Arrow keys (Hue / Alpha) | Decrement / increment the channel by 1 (1% for alpha); Shift or Page steps by 10. |
| Home / End (Hue / Alpha) | Jumps the channel to its extremes. |
| Arrow keys (Swatches) | Moves focus among the preset options. |
| Space / Enter (Swatches) | Applies the focused preset. |