If you answer yes, we store and analyse information that helps us improve the website. You can change your choice at any time at the bottom of the page. More about what we store and why.

We also store necessary information that cannot be opted out of. This makes the website work and keeps it secure.

Skip to main content

What are you looking for?

Try searching for…

Components

Select

Select allows users to choose an option from a list.

Press Enter to start editing
<ds-field class="ds-field">
  <label class="ds-label">Select a mountain</label>
  <select class="ds-input">
    <option value="" disabled="" selected="">Select a mountain …</option>
    <option value="everest">Mount Everest</option>
    <option value="aconcagua">Aconcagua</option>
    <option value="denali">Denali</option>
    <option value="kilimanjaro">Kilimanjaro</option>
    <option value="elbrus">Elbrus</option>
    <option value="vinson">Mount Vinson</option>
    <option value="puncakjaya">Puncak Jaya</option>
    <option value="kosciuszko">Mount Kosciuszko</option>
  </select>
</ds-field>
const PreviewEn = () => {
  return (
    <Field>
      <Label>Select a mountain</Label>
      <Select defaultValue=''>
        <Select.Option value='' disabled>
          Select a mountain &hellip;
        </Select.Option>
        <Select.Option value='everest'>Mount Everest</Select.Option>
        <Select.Option value='aconcagua'>Aconcagua</Select.Option>
        <Select.Option value='denali'>Denali</Select.Option>
        <Select.Option value='kilimanjaro'>Kilimanjaro</Select.Option>
        <Select.Option value='elbrus'>Elbrus</Select.Option>
        <Select.Option value='vinson'>Mount Vinson</Select.Option>
        <Select.Option value='puncakjaya'>Puncak Jaya</Select.Option>
        <Select.Option value='kosciuszko'>Mount Kosciuszko</Select.Option>
      </Select>
    </Field>
  );
};

render(<PreviewEn />)

Usage

Append the class name ds-input to <select>.

If you want readonly on a select, you must stop onKeyDown and onMouseDown yourself to prevent changing the state.

CSS variables and data attributes

Sizes are controlled with data-size and colors with data-color. The component will inherit from the closest parent where these are set.

The ds-input class can also be used to style input and textarea.

CSS Variables
NameValue
--dsc-input-accent-colorvar(--ds-color-base-default)
--dsc-input-accent-color--invalidvar(--ds-color-danger-text-subtle)
--dsc-input-backgroundvar(--ds-color-neutral-surface-default)
--dsc-input-background--readonlyvar(--ds-color-neutral-surface-tinted)
--dsc-input-border-colorvar(--ds-color-neutral-border-default)
--dsc-input-border-color--readonlyvar(--ds-color-neutral-border-subtle)
--dsc-input-border-radiusvar(--ds-border-radius-md)
--dsc-input-border-stylesolid
--dsc-input-border-widthvar(--ds-border-width-default)
--dsc-input-border-width--togglemax(var(--ds-border-width-default), var(--ds-size-1) / 2)
--dsc-input-colorvar(--ds-color-neutral-text-default)
--dsc-input-color--readonlyvar(--ds-color-neutral-text-default)
--dsc-input-color-placeholdercolor-mix(in srgb, var(--dsc-input-color), transparent 30%)
--dsc-input-font-sizecalc(max(1rem, 1em))
--dsc-input-line-heightvar(--ds-line-height-md)
--dsc-input-outline-color--hovervar(--ds-color-neutral-border-default)
--dsc-input-outline-color--toggle--hovervar(--dsc-input-accent-color)
--dsc-input-outline-style--hoversolid
--dsc-input-outline-width--hovervar(--ds-border-width-default)
--dsc-input-paddingvar(--dsc-input-padding-block) var(--dsc-input-padding-inline)
--dsc-input-padding-blockvar(--ds-size-2)
--dsc-input-padding-inlinevar(--ds-size-3)
--dsc-input-sizevar(--ds-size-12)
--dsc-input-size--togglevar(--ds-size-6)
--dsc-input-stroke-colorvar(--ds-color-base-contrast-default)
--dsc-input-stroke-color--invalidvar(--ds-color-danger-base-contrast-default)
--dsc-input-stroke-width0.05em
Data Attributes
NameValue
data-widthauto

Example

Grouping

You can use <optgroup> to group options into categories, making long lists more manageable and easier to navigate.

ReadOnly

<select> is always :read-only, and does not support this in the same way as input types you can type into.

If you set aria-readonly on a <select>, we ensure that it behaves as if it has read-only access, by preventing onKeyDown and onMouseDown.

The user will still be able to focus on the element.

React

Select

readOnly
Description

Defines if the select is readOnly @deprecated Use `aria-readonly` instead.

Type
boolean
Default
false
width
Description

Defines the width of Select, where "auto" matches the content width.

Type
"full" | "auto"
Default
full
NameTypeDefaultDescription
readOnlybooleanfalse

Defines if the select is readOnly @deprecated Use `aria-readonly` instead.

width"full" | "auto"full

Defines the width of Select, where "auto" matches the content width.

SelectOptgroup

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

SelectOption

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

Edit this page on github.com (opens in a new tab)