Color Select
<zn-color-select>
ZnColorSelect
A simple color picker. The dropdown lists color swatches with names; the closed control shows only the selected color’s swatch.
<zn-color-select label="Color" name="color"></zn-color-select>
Examples
With a Default Value
Set the selected color with the value attribute (lowercase color name).
<zn-color-select label="Color" name="color" value="blue"></zn-color-select>
Clearable
Add the clearable attribute to show a clear button when a color is selected.
<zn-color-select label="Color" name="color" value="green" clearable></zn-color-select>
Help Text
<zn-color-select label="Color" name="color" help-text="Pick a color for the label."></zn-color-select>
Events
Listen for zn-input to react when a color is picked, and read the new color from
value. zn-clear fires when the clear button empties it.
Selected: none
<zn-color-select class="color-select-events" label="Color" clearable></zn-color-select> <p>Selected: <code class="color-select-events-out">none</code></p> <script type="module"> const select = document.querySelector('.color-select-events'); const out = document.querySelector('.color-select-events-out'); select.addEventListener('zn-input', () => out.textContent = select.value || 'none'); select.addEventListener('zn-clear', () => out.textContent = 'none'); </script>
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
name
|
The name of the select. Used for form submission. |
string
|
- | |
value
|
The selected color (lowercase name, e.g. “red”). Used for form submission. |
string
|
''
|
|
label
|
The select’s label. |
string
|
''
|
|
helpText
help-text
|
The select’s help text. |
string
|
''
|
|
disabled
|
Disables the select. |
|
boolean
|
false
|
required
|
Makes the select a required field. |
|
boolean
|
false
|
clearable
|
Shows a clear button when a color is selected. |
boolean
|
false
|
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Events
| Name | React Event | Description | Event Detail |
|---|---|---|---|
zn-input |
|
Emitted when the selected color changes. | - |
zn-clear |
|
Emitted when the clear button is activated. | - |
Parts
| Name | Description |
|---|---|
swatch |
The color swatch shown in the closed control. |
combobox |
The container that wraps the swatch and expand button (forwarded from zn-select). |
form-control-help-text |
The help text’s wrapper (forwarded from zn-select). |
form-control-input |
The select’s wrapper (forwarded from zn-select). |
Dependencies
This component automatically imports the following dependencies.
<zn-icon><zn-opt-group><zn-option><zn-popup><zn-select><zn-tag>