Logo

ColorPicker

ColorPicker enables users to choose colors by specifying RGB, HSL, or HEX values.

Using ColorPicker

This component allows you to edit or select a color using RGB, HSL, or CSS HEX notation. It displays a popup over the UI and lets you use the mouse or keyboard to edit or select a color.
<App>
  <ColorPicker id="colorPicker" label="Select your favorite color" />
  <Text>Selected color: {colorPicker.value}</Text>
</App>
Example: using ColorPicker
<App>
  <ColorPicker id="colorPicker" label="Select your favorite color" />
  <Text>Selected color: {colorPicker.value}</Text>
</App>

Properties

autoFocus (default: false)

If this property is set to true, the component gets the focus automatically when displayed.

enabled (default: true)

This boolean property value indicates whether the component responds to user events (true) or not (false).

initialValue

This property sets the component's initial value.
<App>
  <ColorPicker 
    id="colorPicker" 
    label="Select your favorite color" 
    initialValue="#ff0080"
    />
  <Text>Selected color: {colorPicker.value}</Text>
</App>
Example: using ColorPicker
<App>
  <ColorPicker 
    id="colorPicker" 
    label="Select your favorite color" 
    initialValue="#ff0080"
    />
  <Text>Selected color: {colorPicker.value}</Text>
</App>

label

This property sets the label of the component. If not set, the component will not display a label.

labelBreak (default: true)

This boolean value indicates whether the ColorPicker label can be split into multiple lines if it would overflow the available label width.

labelPosition (default: "top")

Places the label at the given position of the component.
Available values:
ValueDescription
startThe left side of the input (left-to-right) or the right side of the input (right-to-left)
endThe right side of the input (left-to-right) or the left side of the input (right-to-left)
topThe top of the input (default)
bottomThe bottom of the input

labelWidth

This property sets the width of the ColorPicker component's label. If not defined, the label's width will be determined by its content and the available space.

readOnly (default: false)

Set this property to true to disallow changing the component value.
<App>
  <ColorPicker initialValue="#ffff00" label="Cannot be edited" readOnly />
</App>
Example: readOnly
<App>
  <ColorPicker initialValue="#ffff00" label="Cannot be edited" readOnly />
</App>

required (default: false)

Set this property to true to indicate it must have a value before submitting the containing form.

validationStatus (default: "none")

This property allows you to set the validation status of the input component.
Available values:
ValueDescription
validVisual indicator for an input that is accepted
warningVisual indicator for an input that produced a warning
errorVisual indicator for an input that produced an error
<App>
  <ColorPicker initialValue="#c0c0ff" label="Valid" validationStatus="valid" />
  <ColorPicker initialValue="#c0c0ff" label="Warning" validationStatus="warning" />
  <ColorPicker initialValue="#c0c0ff" label="Error" validationStatus="error" />
</App>
Example: validationStatus
<App>
  <ColorPicker initialValue="#c0c0ff" label="Valid" validationStatus="valid" />
  <ColorPicker initialValue="#c0c0ff" label="Warning" validationStatus="warning" />
  <ColorPicker initialValue="#c0c0ff" label="Error" validationStatus="error" />
</App>

Events

didChange

This event is triggered when value of ColorPicker has changed.

gotFocus

This event is triggered when the ColorPicker has received the focus.

lostFocus

This event is triggered when the ColorPicker has lost the focus.

Exposed Methods

focus

Focus the ColorPicker component.
Signature: focus(): void

setValue

This method sets the current value of the ColorPicker.
Signature: set value(value: string): void
  • value: The new value to set for the color picker.
<App>
  <App>
    <ColorPicker 
      id="colorPicker" 
      label="Select your favorite color" 
      initialValue="#808080" />
    <HStack>
      <Button
        label="Set to red"
        onClick="colorPicker.setValue('#ff0000')" />
      <Button
        label="Set to green"
        onClick="colorPicker.setValue('#00c000')" />
      <Button
        label="Set to blue"
        onClick="colorPicker.setValue('#0000ff')" />
    </HStack>
  </App>
</App>
Example: setValue
<App>
  <App>
    <ColorPicker 
      id="colorPicker" 
      label="Select your favorite color" 
      initialValue="#808080" />
    <HStack>
      <Button
        label="Set to red"
        onClick="colorPicker.setValue('#ff0000')" />
      <Button
        label="Set to green"
        onClick="colorPicker.setValue('#00c000')" />
      <Button
        label="Set to blue"
        onClick="colorPicker.setValue('#0000ff')" />
    </HStack>
  </App>
</App>

value

This method returns the current value of the ColorPicker.
Signature: get value(): string

Styling

Theme Variables

VariableDefault Value (Light)Default Value (Dark)
backgroundColor-ColorPickernonenone
borderColor-ColorPicker-defaultnonenone
borderColor-ColorPicker-default--focusnonenone
borderColor-ColorPicker-default--hovernonenone
borderColor-ColorPicker-errornonenone
borderColor-ColorPicker-error--focusnonenone
borderColor-ColorPicker-error--hovernonenone
borderColor-ColorPicker-successnonenone
borderColor-ColorPicker-success--focusnonenone
borderColor-ColorPicker-success--hovernonenone
borderColor-ColorPicker-warningnonenone
borderColor-ColorPicker-warning--focusnonenone
borderColor-ColorPicker-warning--hovernonenone
borderRadius-ColorPicker-defaultnonenone
borderRadius-ColorPicker-errornonenone
borderRadius-ColorPicker-successnonenone
borderRadius-ColorPicker-warningnonenone
borderStyle-ColorPicker-defaultnonenone
borderStyle-ColorPicker-errornonenone
borderStyle-ColorPicker-successnonenone
borderStyle-ColorPicker-warningnonenone
borderWidth-ColorPicker-defaultnonenone
borderWidth-ColorPicker-errornonenone
borderWidth-ColorPicker-successnonenone
borderWidth-ColorPicker-warningnonenone
boxShadow-ColorPicker-defaultnonenone
boxShadow-ColorPicker-default--focusnonenone
boxShadow-ColorPicker-default--hovernonenone
boxShadow-ColorPicker-errornonenone
boxShadow-ColorPicker-error--focusnonenone
boxShadow-ColorPicker-error--hovernonenone
boxShadow-ColorPicker-successnonenone
boxShadow-ColorPicker-success--focusnonenone
boxShadow-ColorPicker-success--hovernonenone
boxShadow-ColorPicker-warningnonenone
boxShadow-ColorPicker-warning--focusnonenone
boxShadow-ColorPicker-warning--hovernonenone
This site is an XMLUI™ app.