Skip to main content
Design system

Select

A select is a type of form element that provides a method for choosing one item from a list of options.

Bundle size: 9.68 kB
Install:
npm install @washingtonpost/wpds-ui-kit
|Copy
Usage:
import { Select } from "@washingtonpost/wpds-ui-kit"
|Copy
Source:  View on Github

Anatomy

  1. Selected value
  2. Label/placeholder
  3. Helper text (optional)
  4. Chevron icon (actionable)
  5. Border
  6. Check icon (indicates selected option)
  7. Options list
  8. Option hover state
  9. Option

Options

No styling options

The select component currently only supports one size and variant.


Behavior

Options list (Active)

Clicking or tapping the select field initiates the active state, revealing an options list that consists of a set of values. When in the active state, the label/placeholder is reduced in size and the chevron icon rotates 180 degrees, pointing upwards.

The options list may contain as many values as needed and becomes scrollable if there are more options than what is currently in view.

Making a selection (Active)

The options list can be navigated by mouse hover or via the up/down arrow keys (indicated by a faint highlight). clicking or tapping an option in the list will select the chosen value (indicated by the check icon)

Once a selection is made, the chosen value is displayed within the select field and the options list is automatically dismissed. Selection can also be achieved by pressing the Enter/Return key while an option is highlighted. to cancel selection/dismiss the options list, click or tap outside the element or press the Esc key.

Select groups

The options list can be segmented into groups. Grouping options within a select field can be helpful for creating categories or subcategories of similar items.

Text overflow

Overflow of the selected value is indicated by an ellipsis

Show required

Focus

Error

Success

Disabled


Accessibility

ARIA

Assistive technologies (e.g. screen readers) announce the element clearly to users, including its role, name and state.

Accessibility

The listbox position is adjusted (i.e. does not get cut off the screen).


API Reference

SelectRoot

PropDescriptionTypeDefaultRequired
childrenUsed to insert select elements into the root component
enum
ReactNode
----False
cssWPDS provides a css prop for overriding styles easily. It’s like the style attribute, but it supports tokens, media queries, nesting and token-aware values. All WPDS Components include a css prop. Use it to pass in overrides.
CSS
----False
disabledThe underlying input element disabled attribute
enum
boolean
----False
errorIndicates there is an error
enum
boolean
----False
errorMessageText displayed below the select to describe the cause of the error
enum
ReactNode
----False
helperTextText displayed below the input to provide additional context
enum
ReactNode
----False
onValueChangeEvent handler called when the value changes.
enum
((value: string) => void) | ((state: string) => void)
----False
requiredThe select element's required attribute
enum
boolean
----False
successIndicates there is a success
enum
boolean
----False
valueThe controlled value of the select. Should be used in conjunction with onValueChange
string
----False
defaultValueThe value of the select when initially rendered. Use when you do not need to control the state of the select.
string
----False
openforce overlay open
enum
boolean
----False

SelectContent

PropDescriptionTypeDefaultRequired
childrenUsed to insert select elements into the root component
enum
ReactNode
----False
cssWPDS provides a css prop for overriding styles easily. It’s like the style attribute, but it supports tokens, media queries, nesting and token-aware values. All WPDS Components include a css prop. Use it to pass in overrides.
{} & { alignContent?: Globals | ScaleValue | Index | AlignContent; alignItems?: Globals | ScaleValue | Index | AlignItems; ... 425 more ...; vectorEffect?: Globals | ... 2 more ... | VectorEffect; } & ... 7 more ... & { ...; }
----False
asChild
enum
boolean
----False
onEscapeKeyDownEvent handler called when the escape key is down. Can be prevented.
(event: KeyboardEvent) => void
----False
onPointerDownOutsideEvent handler called when the a `pointerdown` event happens outside of the `DismissableLayer`. Can be prevented.
(event: PointerDownOutsideEvent) => void
----False
onCloseAutoFocusEvent handler called when auto-focusing on close. Can be prevented.
(event: Event) => void
----False

SelectGroup

PropDescriptionTypeDefaultRequired
childrenUsed to insert select elements into the root component
enum
ReactNode
----False
cssWPDS provides a css prop for overriding styles easily. It’s like the style attribute, but it supports tokens, media queries, nesting and token-aware values. All WPDS Components include a css prop. Use it to pass in overrides.
{} & { alignContent?: Globals | ScaleValue | Index | AlignContent; alignItems?: Globals | ScaleValue | Index | AlignItems; ... 425 more ...; vectorEffect?: Globals | ... 2 more ... | VectorEffect; } & ... 7 more ... & { ...; }
----False
labelThe value of the select when initially rendered. Use when you do not need to control the state of the select.
string
----False
none
enum
boolean | true
----False

SelectItem

PropDescriptionTypeDefaultRequired
childrenUsed to insert select elements into the root component
enum
ReactNode
----False
disabled
enum
boolean
----False
valueThe value associated with this item
string
----
True
cssWPDS provides a css prop for overriding styles easily. It’s like the style attribute, but it supports tokens, media queries, nesting and token-aware values. All WPDS Components include a css prop. Use it to pass in overrides.
{} & { alignContent?: Globals | ScaleValue | Index | AlignContent; alignItems?: Globals | ScaleValue | Index | AlignItems; ... 425 more ...; vectorEffect?: Globals | ... 2 more ... | VectorEffect; } & ... 7 more ... & { ...; }
----False
asChild
enum
boolean
----False
textValue
string
----False

SelectLabel

PropDescriptionTypeDefaultRequired
isFloating
enum
boolean | true
----False
isDisabled
enum
boolean | true
----False
childrenUsed to insert select elements into the root component
enum
ReactNode
----False
cssWPDS provides a css prop for overriding styles easily. It’s like the style attribute, but it supports tokens, media queries, nesting and token-aware values. All WPDS Components include a css prop. Use it to pass in overrides.
CSS
----False

SelectTrigger

PropDescriptionTypeDefaultRequired
childrenUsed to insert select elements into the root component
enum
ReactNode
----False
asChild
enum
boolean
----False
success
enum
boolean | true
----False
error
enum
boolean | true
----False
isInvalid
enum
boolean | true
----False
isDisabled
enum
boolean | true
----False
cssWPDS provides a css prop for overriding styles easily. It’s like the style attribute, but it supports tokens, media queries, nesting and token-aware values. All WPDS Components include a css prop. Use it to pass in overrides.
CSS
----False

SelectValue

PropDescriptionTypeDefaultRequired
isDisabled
enum
boolean | true
----False
placeholder
enum
ReactNode & string
----False
childrenUsed to insert select elements into the root component
enum
ReactNode
----False
asChild
enum
boolean
----False
cssWPDS provides a css prop for overriding styles easily. It’s like the style attribute, but it supports tokens, media queries, nesting and token-aware values. All WPDS Components include a css prop. Use it to pass in overrides.
CSS
----False