Skip to content

Swatch ​

Inline color blocks for quick preset-color selection and display — for theme colors, tag colors, favorite colors and other "pick a color without opening a panel" scenarios. oas-swatch is the color block; oas-swatch-group is the selection group (single-select radio semantics / multi-select checkbox semantics, roving keyboard navigation).

Basic usage ​

Single-select group: click a swatch to select it (selected state = outer ring); oas-change carries the selected value.

Selected state

Single select

Current: —

Multiple select ​

With multiple, the group uses checkbox semantics; value is a comma-separated list of selected values (prefer preset names or hex colors for the multiple-value channel — color values containing commas, such as rgb(1,2,3), conflict with the comma separator and are not recommended inside a multiple group).

Multiple select

Current: []

Shapes and sizes ​

shape has three forms (square / rounded / circle); size has five steps (xs / small / medium / large / xl).

Shapes and sizes

Nothing and mixed ​

nothing marks a no-color/transparent swatch (checkerboard base); mixed marks a multi-color swatch (mosaic, for merged multi-value scenarios).

Nothing and mixed

Controlled selection (value) ​

The group value is a controlled channel: setting the attribute externally updates the selected state immediately.

Controlled value

Select redSelect blue

Keyboard navigation ​

Tab enters the group (single roving stop) → arrow keys move focus (horizontal keys mirror in RTL) → Enter/Space selects → Home/End jump to first/last. Disabled swatches are skipped in the roving order.

API ​

oas-swatch ​

Attributes ​

AttributeDescriptionTypeDefault
aria-labelAccessible name override (host-written value takes top priority)——
colorFill color (any CSS color or one of 11 preset names, unified color protocol)string—
disabledDisable the swatch (not clickable, not focusable)boolean—
labelAccessible name (defaults to i18n swatch.color + the color value)——
mixedMixed-color indicator (mosaic, for merged multi-value scenarios)boolean—
nothingNo-color/transparent indicator (checkerboard base, color-independent)boolean—
selectedControlled selected state (outer ring; driven by oas-swatch-group inside a group)boolean—
shapeShape: square / rounded (default) / circlestringrounded
sizeSide-length step: xs / small / medium (default) / large / xlstring—

Property (JS property; see each row for attribute reflection) ​

PropertyDescriptionTypeDefault
valueCurrent value: the swatch color identifier (i.e. the color attribute)string—

Events ​

EventDescription
oas-clickClick, detail: { color } (intercepted by the group which emits the group-level oas-change)

oas-swatch-group ​

Attributes ​

AttributeDescriptionTypeDefault
aria-labelGroup accessible name (locale fallback by default)——
disabledDisable the whole group (propagated to children)boolean—
multipleMultiple-select mode (checkbox semantics)boolean—
valueCurrent value: child swatch's color in single select; comma-separated list in multiple selectstring | string[]—

Property (JS property; see each row for attribute reflection) ​

PropertyDescriptionTypeDefault
valueCurrent value: the selected color string, or an array of colors when multiplestring | string[]—

Events ​

EventDescription
oas-changeSelection change, detail: { value: string | string[] }

Slots ​

NameDescription
defaultSwatch children (<oas-swatch>)

Released under the MIT OR Apache-2.0 License.