Skip to main content

Components

Select

Select allows users to choose an option from a list.

readOnly
Description

Defines if the select is readOnly

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

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.

Use

Example

Grouping

You can use Select.Optgroup to group options into categories, making long lists more manageable and easier to navigate.

Disabled

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 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.

HTML

Append the class name ds-select 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

The ds-input class can be used to style Input and Textarea as well.

CSS Variables
NameValue
--dsc-input-padding-blockvar(--ds-size-2)
--dsc-input-padding-inlinevar(--ds-size-3)
--dsc-input-paddingvar(--dsc-input-padding-block) var(--dsc-input-padding-inline)
--dsc-input-size--togglevar(--ds-size-6)
--dsc-input-sizevar(--ds-size-12)
--dsc-input-background--readonlyvar(--ds-color-neutral-surface-tinted)
--dsc-input-backgroundvar(--ds-color-neutral-surface-default)
--dsc-input-border-color--readonlyvar(--ds-color-neutral-border-subtle)
--dsc-input-border-colorvar(--ds-color-neutral-border-default)
--dsc-input-border-stylesolid
--dsc-input-border-width--togglemax(var(--ds-border-width-default),calc(var(--ds-size-1)/2))
--dsc-input-border-widthvar(--ds-border-width-default)
--dsc-input-outline-color--hovervar(--ds-color-neutral-border-default)
--dsc-input-outline-color--toggle--hovervar(--dsc-input-accent-color)
--dsc-input-outline-width--hovervar(--ds-border-width-default)
--dsc-input-outline-style--hoversolid
--dsc-input-color--readonlyvar(--ds-color-neutral-text-default)
--dsc-input-colorvar(--ds-color-neutral-text-default)
--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
--dsc-input-accent-colorvar(--ds-color-base-default)
--dsc-input-accent-color--invalidvar(--ds-color-danger-text-subtle)
--dsc-input-line-heightvar(--ds-line-height-md)
Data Attributes
NameValue
data-widthauto
Edit this page on github.com (opens in a new tab)