Skip to content

Select ​

@ew-color-picker/select ships two pieces:

  1. Plugin ewColorPickerSelect — renders a dropdown in the bottom row when selectItems is provided;
  2. Component Select — a standalone controlled dropdown that other plugins can reuse (for example a gradient editor).
ItemValue
Package@ew-color-picker/select
pluginNameewColorPickerSelect
applyOrderPost
Mount pointpanelContainer → .ew-color-picker-bottom-row (only when items are provided)
Instancecore.plugins.ewColorPickerSelect

Extra stylesheet required

ts
import '@ew-color-picker/style/dist/select.css'

Without it the dropdown is unstyled.

Plugin options ​

OptionTypeDefaultDescription
showSelectbooleantrueSet false to hide the dropdown
selectItemsSelectOption[][]Options to render; an empty list renders nothing
selectValuestring | numberundefinedInitially selected value
selectPlaceholderstringundefinedText shown when no value is selected
selectClearablebooleantrueShow a clear icon once a value is selected
onSelectChange(value, option) => void—Called after the user picks an option
onSelectClear() => void—Called after the user clears the selection
ts
import ewColorPicker from '@ew-color-picker/core'
import Select from '@ew-color-picker/select'

ewColorPicker.use(Select)

new ewColorPicker({
  el: '#app',
  selectItems: [
    { label: 'Linear', value: 'linear' },
    { label: 'Radial', value: 'radial' },
  ],
  onSelectChange: (value) => console.log(value),
  onSelectClear: () => console.log('cleared'),
})

Plugin methods ​

MethodSignatureDescription
createSelect(options) => SelectCreate a component instance
updateOptions() => voidRe-read options and re-render
run() => voidRender the dropdown when items are configured
destroy() => voidRemove the dropdown and release events

Select component ​

ts
import { Select } from '@ew-color-picker/select'

Options ​

OptionTypeDefault
valuestring | numberundefined
itemsSelectOption[][]
placeholderstring''
disabledbooleanfalse
size'small' | 'default' | 'large''default'
prefixstring'ew-'
clearablebooleantrue
onChange(value, option) => void—
onClear() => void—
onOpen / onClose() => void—

SelectOption is { label: string; value: string | number; disabled?: boolean }.

The clear icon only appears when clearable is true and a value is selected. Clicking it resets the value to undefined, restores the placeholder text, closes the dropdown and fires onClear. Disabled selects never show the clear icon.

Methods ​

MethodSignatureDescription
getValue() => string | number | undefinedCurrent value
setValue(value, triggerChange?) => voidSet the value; pass false to skip onChange
clear(triggerChange?) => voidReset to empty; pass false to skip onClear
setItems(items) => voidReplace the option list
setDisabled(disabled) => voidToggle the disabled state
open / close() => voidControl the dropdown
isDropdownOpen() => booleanWhether the dropdown is open
getElement() => HTMLElementRoot node
destroy() => voidUnbind events and remove the node

Keyboard and accessibility ​

KeyAction
ArrowDown / ArrowUpOpen the dropdown or move the active option
EnterSelect the active option
EscapeClose the dropdown
TabClose and move focus away

The trigger exposes aria-haspopup="listbox" / aria-expanded, and options use role="option" with aria-selected and aria-disabled.

DOM ​

html
<div class="ew-select ew-select--default">
  <button type="button" class="ew-select__trigger" aria-haspopup="listbox" aria-expanded="false">
    <span class="ew-select__value">Linear</span>
    <span class="ew-select__clear" role="button" aria-label="Clear selection"><svg class="ew-select__clear-icon">…</svg></span>
    <span class="ew-select__arrow"><svg class="ew-select__arrow-icon">…</svg></span>
  </button>
  <div class="ew-select__dropdown" role="listbox">
    <div class="ew-select__option ew-select__option--selected" role="option" data-select-index="0">Linear</div>
    <div class="ew-select__option" role="option" data-select-index="1">Radial</div>
  </div>
</div>