<cs-select>
StableFormsSince 0.1

Selects let users choose one or more values from a dropdown list of predefined options. Use them in forms when a fixed set of choices needs to fit in limited space.

Espresso Latte Cappuccino Cold brew Drip
Espresso Latte Cappuccino Cold brew Drip

This component works with standard <form> elements. See form controls for form submission and client-side validation.

Examples

Label

Use the label attribute to give the select an accessible label. For labels that contain HTML, use the label slot instead.

United States Canada Mexico

Hint

Add a descriptive hint with the hint attribute. For hints that contain HTML, use the hint slot instead.

Novice Intermediate Advanced

Placeholder

Use the placeholder attribute to show prompt text before a selection is made.

Option 1 Option 2 Option 3

Initial Value

Use the selected attribute on individual options to set the initial selection, just like native HTML.

main develop staging

When the multiple attribute is present, add selected to each option that should start selected.

Mushrooms Olives Peppers Onions

Framework users can bind directly to the value property for reactive data binding and form state management.

Appearance

Use the appearance attribute to change the select’s visual style.

outlined filled filled-outlined

Pill

Use the pill attribute to give the select rounded edges.

Option 1 Option 2 Option 3

Size

Use the size attribute to change a select’s size.

Option 1 Option 2 Option 1 Option 2 Option 1 Option 2 Option 1 Option 2 Option 1 Option 2

Disabled

Use the disabled attribute to disable a select.

Option 1 Option 2 Option 3

Clearable

Use the with-clear attribute to let people reset their choice. The clear button only appears once an option is selected.

Option 1 Option 2 Option 3

Multiple

To let people choose more than one option, add the multiple attribute. Pair it with with-clear so a long selection is easy to reset.

Mentions Replies Reactions New followers Releases

Multiple selections can grow the control vertically.
Use the max-options-visible attribute to cap how many tags show at once before the rest collapse into a count.

Grouping Options

Use <cs-divider> to separate groups of options visually. You can also add <small> labels, but note that most assistive technologies won’t announce them.

Frontend TypeScript CSS Backend Go Rust Python

Placement

Set the placement attribute to control where the listbox opens. Valid placements are bottom (default) and top; the actual position may flip to keep the panel in the viewport.

Option 1 Option 2 Option 3

Start & End Decorations

Use the start and end slots to add presentational elements such as <cs-icon> inside the combobox.

Los Angeles New York Tokyo

Custom Tags

When multiple options can be selected, supply custom tags by passing a function to the getTag property. The function runs for each selected option and can return a string of HTML, a Lit template, or an HTMLElement. Its first argument is the <cs-option> element and its second is the tag’s index.

Because custom tags render in a shadow root, style them with the style attribute in your template, or add your own parts and target them with ::part().

Email Phone Chat

Only pass content you trust to getTag().
Unsanitized user input rendered into a tag can result in XSS vulnerabilities.

When using custom tags with with-remove, include the data-value attribute set to the option’s value so the select knows which option to deselect when the tag’s remove button is clicked.

Lazy Loading Options

The select handles options that arrive after the initial render, similar to a native <select>:

  • Empty select with a value: a <cs-select> created without options but given a value starts with an empty value. When an option whose value matches is added later, the select updates to match.
  • Multiple select with partial options: a <cs-select multiple> with an initial value respects only the options present in the DOM. When the remaining selected options load later — and the user hasn’t changed the selection — they’re added automatically.
Bar Baz Add "foo" option

Add "foo" option

Bar Baz Add "foo" option (selected)

Add "foo" option


Reset Show FormData


Throughout, the select prioritizes user interactions and explicit selections over programmatic changes, keeping behavior predictable even with dynamically loaded content.

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/select/select.js';
import './cornerstone/components/select/select.js';
import CsSelect from '@cruglobal/cornerstone-components/react/select/index.js';

Slots

Learn more about using slots.

NameDescription
(default)The listbox options. Must be <cs-option> elements. You can use <cs-divider> to group items visually.
clear-iconAn icon to use in lieu of the default clear icon.
endAn element, such as <cs-icon>, placed at the end of the combobox.
expand-iconThe icon to show when the control is expanded and collapsed. Rotates on open and close.
hintText that describes how to use the input. Alternatively, you can use the hint attribute.
labelThe input's label. Alternatively, you can use the label attribute.
startAn element, such as <cs-icon>, placed at the start of the combobox.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
appearanceappearanceThe select's visual appearance.'filled' | 'outlined' | 'filled-outlined''outlined'Yes
disableddisabledDisables the select control.booleanfalse
formBy default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.HTMLFormElement | null
getTagA function that customizes the tags to be rendered when multiple=true. The first argument is the option, the second is the current tag's index. The function should return either a Lit TemplateResult or a string containing trusted HTML of the symbol to render at the specified value.(option: CsOption, index: number) => TemplateResult | string | HTMLElement
hinthintThe select's hint. If you need to display HTML, use the hint slot instead.string''
labellabelThe select's label. If you need to display HTML, use the label slot instead.string''
maxOptionsVisiblemax-options-visibleThe maximum number of selected options to show when multiple is true. After the maximum, "+n" will be shown to indicate the number of additional items that are selected. Set to 0 to remove the limit.number3
multiplemultipleAllows more than one option to be selected.booleanfalseYes
namenameThe name of the select, submitted as a name/value pair with form data.string | null''Yes
openopenIndicates whether or not the select is open. You can toggle this attribute to show and hide the menu, or you can use the show() and hide() methods and this attribute will reflect the select's open state.booleanfalseYes
pillpillDraws a pill-style select with rounded edges.booleanfalseYes
placeholderplaceholderPlaceholder text to show as a hint when the select is empty.string''
placementplacementThe preferred placement of the select's menu. Note that the actual placement may vary as needed to keep the listbox inside of the viewport.'top' | 'bottom''bottom'Yes
requiredrequiredThe select's required attribute.booleanfalseYes
sizesizeThe select's size.'xs' | 's' | 'm' | 'l' | 'xl''m'Yes
ssrHintssr-hintOnly required for SSR. Set to true if you're slotting in a hint element so the server-rendered markup includes the hint before the component hydrates on the client.booleanfalse
ssrLabelssr-labelOnly required for SSR. Set to true if you're slotting in a label element so the server-rendered markup includes the label before the component hydrates on the client.booleanfalse
validationTargetWhere to anchor native constraint validationundefined | HTMLElement
validatorsValidators are static because they have observedAttributes, essentially attributes to "watch" for changes. Whenever these attributes change, we want to be notified and update the validator.Validator[][]
valuevalueThe select's value. This will be a string for single select or an array for multi-select.
withClearwith-clearAdds a clear button when the select is not empty.booleanfalse

Methods

Learn more about methods.

NameDescriptionArguments
blur()Removes focus from the control.
focus()Sets focus on the control.options: FocusOptions
formStateRestoreCallback()Called when the browser is trying to restore element’s state to state in which case reason is "restore", or when the browser is trying to fulfill autofill on behalf of user in which case reason is "autocomplete". In the case of "restore", state is a string, File, or FormData object previously set as the second argument to setFormValue.state: string | File | FormData | null, reason: 'autocomplete' | 'restore'
hide()Hides the listbox.
resetValidity()Reset validity is a way of removing manual custom errors and native validation.
setCustomValidity()Do not use this when creating a "Validator". This is intended for end users of components. We track manually defined custom errors so we don't clear them on accident in our validators.message: string
show()Shows the listbox.

Events

Learn more about events.

NameDescription
blurEmitted when the control loses focus.
changeEmitted when the control's value changes.
cs-after-hideEmitted after the select's menu closes and all animations are complete.
cs-after-showEmitted after the select's menu opens and all animations are complete.
cs-clearEmitted when the control's value is cleared.
cs-hideEmitted when the select's menu closes.
cs-invalidEmitted when the form control has been checked for validity and its constraints aren't satisfied.
cs-showEmitted when the select's menu opens.
focusEmitted when the control gains focus.
inputEmitted when the control receives input.

CSS Custom Properties

Learn more about CSS custom properties.

NameDescriptionDefault
--hide-durationThe duration of the hide animation.var(--cs-transition-fast)
--show-durationThe duration of the show animation.var(--cs-transition-fast)
--tag-max-sizeWhen using multiple, the max size of tags before their content is truncated.10ch

Custom States

Learn more about custom states.

NameDescriptionCSS selector
blankThe select is empty.:state(blank)

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
clear-buttonThe clear button.::part(clear-button)
comboboxThe container the wraps the start, end, value, clear icon, and expand button.::part(combobox)
display-inputThe element that displays the selected option's label, an <input> element.::part(display-input)
endThe container that wraps the end slot.::part(end)
expand-iconThe container that wraps the expand icon.::part(expand-icon)
form-controlThe form control that wraps the label, input, and hint.::part(form-control)
form-control-inputThe select's wrapper.::part(form-control-input)
form-control-labelThe label.::part(form-control-label)
hintThe hint's wrapper.::part(hint)
listboxThe listbox container where options are slotted.::part(listbox)
startThe container that wraps the start slot.::part(start)
tagThe individual tags that represent each multiselect option.::part(tag)
tag__contentThe tag's content part.::part(tag__content)
tag__remove-buttonThe tag's remove button.::part(tag__remove-button)
tag__remove-button__buttonThe tag's remove button's exported button part.::part(tag__remove-button__button)
tagsThe container that houses option tags when multiselect is used.::part(tags)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.