Liking cljdoc? Tell your friends :D

x-color-picker

A color picker component with a 2D saturation/brightness area, hue strip, optional alpha channel, preset swatches, eyedropper support, and clipboard copy. Supports inline and popover display modes.

Tag name

<x-color-picker></x-color-picker>

Attributes

AttributeTypeDefaultDescription
valuestring"#000000"Current color as #rrggbb or #rrggbbaa
alphabooleanabsentShow alpha channel strip
swatchesstringabsentComma-separated preset hex colors
disabledbooleanabsentDisable all interaction
readonlybooleanabsentPrevent value changes
namestringabsentForm field name
modestring"inline""inline" (always visible) or "popover"
openbooleanabsentPopover open state (popover mode only)
labelstringabsentAccessible label for the color area

Properties

PropertyTypeReflects attribute
valuestringvalue
alphabooleanalpha
swatchesstringswatches
disabledbooleandisabled
readOnlybooleanreadonly
namestringname
modestringmode
openbooleanopen
labelstringlabel

Events

EventBubblesComposedCancelableDetail
x-color-picker-inputtruetruefalse{ value, h, s, l, a }
x-color-picker-changetruetruetrue{ value, h, s, l, a }
  • input fires continuously during drag interaction (area, hue strip, alpha strip).
  • change fires when the user commits a value (pointer up, Enter key on hex input, swatch click).

Slots

None.

Parts

PartDescription
containerOuter wrapper
triggerPopover trigger button (popover mode)
trigger-swatchColor swatch inside trigger
panelPicker panel
area2D saturation/brightness gradient
area-thumbArea draggable thumb
hue-stripHue gradient bar
hue-thumbHue strip thumb
alpha-stripAlpha gradient bar
alpha-gradientAlpha gradient overlay
alpha-thumbAlpha strip thumb
controlsControls row
previewColor preview swatch
preview-colorPreview swatch inner color
hex-inputHex value text input
eyedropperEyedropper button (Chrome/Edge only)
copyCopy to clipboard button
swatchesPreset swatches grid
swatchIndividual preset swatch button

CSS Custom Properties

PropertyDefaultDescription
--x-color-picker-width240pxOverall width
--x-color-picker-area-height160pxColor area height
--x-color-picker-strip-height14pxHue/alpha strip height
--x-color-picker-swatch-size28pxPreset swatch size
--x-color-picker-radiusvar(--x-radius-md, 8px)Border radius
--x-color-picker-gap10pxInternal spacing

Accessibility

  • The color area has role="slider" with aria-valuetext describing the current color in human-readable format.
  • The hue strip has role="slider" with aria-valuemin="0" and aria-valuemax="360".
  • The alpha strip has role="slider" with aria-valuemin="0" and aria-valuemax="100".
  • Preset swatches use role="option" inside a role="listbox" container.
  • All interactive elements are keyboard accessible via Tab.

Keyboard Interaction

KeyContextAction
Arrow Left/RightColor areaAdjust saturation by 1 (10 with Shift)
Arrow Up/DownColor areaAdjust brightness by 1 (10 with Shift)
Arrow Left/RightHue stripAdjust hue by 1 (10 with Shift)
Home / EndHue stripSet hue to 0 / 360
Arrow Left/RightAlpha stripAdjust alpha by 0.01 (0.1 with Shift)
Home / EndAlpha stripSet alpha to 0 / 1
EnterHex inputApply typed hex value
EscapePopoverClose popover
TabAllCycle through interactive elements

Examples

HTML

<!-- Inline (default) -->
<x-color-picker value="#3b82f6"></x-color-picker>

<!-- With alpha channel -->
<x-color-picker value="#3b82f680" alpha></x-color-picker>

<!-- With preset swatches -->
<x-color-picker swatches="#ef4444,#f59e0b,#10b981,#3b82f6,#8b5cf6"></x-color-picker>

<!-- Popover mode -->
<x-color-picker mode="popover" value="#10b981"></x-color-picker>

<!-- Disabled -->
<x-color-picker value="#3b82f6" disabled></x-color-picker>

JavaScript

const picker = document.querySelector('x-color-picker');

picker.addEventListener('x-color-picker-change', (e) => {
  console.log('Color:', e.detail.value);
  console.log('HSL:', e.detail.h, e.detail.s, e.detail.l);
});

// Set value programmatically
picker.value = '#ff5500';

Form Integration

<form>
  <x-color-picker name="accent-color" value="#3b82f6"></x-color-picker>
  <button type="submit">Save</button>
</form>

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close