Skip to content

Selector

@astryxdesign/core v0.7.1 · Selector

Usage ​

Selector opens a list when the trigger is clicked. Choosing one option closes the list. It can filter the list, clear the current value, and disable individual options.

Pass the options and bind the value:

vue
<script setup lang="ts">
import { Selector } from '@astryx-vue/core/Selector'
import { ref } from 'vue'

const selected = ref(null)
const options = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana' },
  { value: 'cherry', label: 'Cherry' },
]
</script>

<template>
  <Selector v-model="selected" :options="options" placeholder="Select a fruit" />
</template>

Each option has a value and a label. Set disabled to skip an option, or description to add a second line of text.

searchable shows a search field that filters the list. hasClear adds a clear button next to the current value; clearable is the older name. The menu is at least as wide as the trigger, and grows when an option label is longer.

A read-only field keeps the current value, stays focusable, and still submits with the form. It does not open, and it has no clear button or chevron. It does not dim. Disabled wins when both are set. While loading, the trigger shows a spinner and the menu does not claim that nothing was found. An empty catalog and a search with no matches use different sentences. The check mark sits at the end of a selected row by default, and can move to the start. An unselected row does not reserve space for it. disabledMessage explains a disabled field: a tooltip follows hover and keyboard focus, the trigger stays focusable through aria-disabled, and the list still does not open.

Arrow keys move the highlight. Home and End jump to the ends. Enter selects the highlighted option, and Escape closes the list. Once the search field is open, the arrow keys and Enter apply there, and Space still types a character.

Built-in strings such as the placeholder and the empty state are English. Call provideAstryxLocale('zh-CN') to use the Chinese strings.

Best Practices ​

GuidelinePractice
DoEnable search when options exceed 10 items to help users find items quickly.
DoProvide a clear button for non-required fields so users can deselect.
DoUse concise, clear option labels and avoid overly long text.
Don'tPut more than 100 options in a selector; consider pagination or async loading.
Don'tUse selector for multi-select; use a dedicated multi-select component instead.

Anatomy

ElementDescription
FieldStandalone Field shell that provides the label and optional supporting content; omitted inside InputGroup.
TriggerPainted control that displays the current selection or placeholder and opens the selection surface when editable.
Icon-rendered start iconOptional leading semantic icon or icon component rendered through Icon.
Caller-rendered start contentOptional arbitrary slot content rendered directly at the start of the trigger.
Trigger clear buttonShared clear action that removes the selected value when clearable is set.
Status iconStatus glyph shown in place of the disclosure indicator for attached or tooltip status.
Indicator iconTrailing chevron shown when status presentation does not replace it; reflects collapsed or expanded state.
Search rowPanel header with a borderless search input and optional clear action.
Search iconLeading magnifier rendered through Icon inside the search row.
Search clear buttonShared clear action shown in the search row while a query is present.
Option rowSelectable row for one supplied option.
Default option contentLabel, description, and icon drawn from the option data when the option slot is not provided.
Option slot contentContent supplied through the option slot, in place of the default label and description.
Option selection indicatorResolved selection mark rendered for each option in its checked or unchecked state. Its layout space collapses when the resolved indicator draws nothing.
Option dividerDivider supplied in the public options data to separate adjacent option groups.
Section headingVisible heading for a labeled group of option rows.
Empty stateMessage shown when the shared panel content has no options or no search matches.
Pointer popupAnchored painted surface that hosts the shared panel content for popover presentation.
Touch sheet headingHeading above the shared panel content in bottom-sheet presentation.
Touch sheetBottomSheet surface that hosts the same panel content for bottom-sheet presentation.

Examples ​

Bottom sheet

Team

Presents a single-selection list in a bottom sheet for compact touch interfaces.

Clearable

A clear button resets the selected value.

Ghost toolbar

This setting affects all users

A borderless selector sits with ghost buttons in a toolbar.

Secondary

The secondary trigger rests like a secondary button: no border, and a neutral fill.

Option actions

An option can carry an action. Activating it does not change the selection. Once any option has an action, the menu becomes two columns.

Grouped sections

Options are grouped into labeled sections.

Option descriptions

Default trigger: one line at the size token.
A stacked value: the description gets its own line, and the trigger grows by exactly one line.

Options carry a description, so the menu draws a two-line row. A one-line value stays at the size token. A two-line value grows by one line. Inside an input group the value stays on one line.

Validation states

Please select a role
Viewer has limited access

Error, warning, and success validation states.

Read-only, disabled, loading, and search

Read only
Only the owner of this list can change it

Read-only keeps the current value. Loading does not claim the catalog is empty. Required is marked beside the label. A disabled field explains itself in a tooltip on hover or keyboard focus and stays focusable. A search with no matches uses its own sentence, and the check mark can sit at the start of the row.