Select
BasicInputs
<co-select>Select picks one value from a short fixed list, such as Provider, Location or Status filters.
import { Select } from 'health-components';
Examples
Showcase
With Placeholder
Small
Read Only
Usage
<Select label="Provider" options={["All", ...providers]} value={provider} onChange={e => setProvider(e.target.value)} />
When to use
- Up to about 15 known options.
When not to use
- Long or searchable lists (patients, codes, payers): Combobox.
- Two to four options shown at once: SegmentedControl or RadioGroup.
Variants and states
| Variant | What it is |
|---|---|
| default | Native select with a chevron. |
| sm | 30px, for table toolbars and rows-per-page. |
| error | Red border and message. |
| readOnly | Disabled with lock icon and lock line. |
Accessibility
- Native select keeps platform keyboard and screen reader behaviour.
Do and don't
- Do: "All" as the first option of a filter.
- Don't: A select with one option.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label * | string | — | Visible label; required |
options * | Array<string | SelectOption> | — | Array<string | {value, label}>; required |
placeholder | string | none | Text of a first empty option ("Choose one") |
size | 'sm' | 'md' | 'md' | 'sm' | 'md' |
error | string | none | Error message (as TextField) |
helper | string | none | Muted hint under the field (as TextField) |
required | boolean | false | Red asterisk plus aria-required (as TextField) |
readOnly | boolean | false | Read-only lock state: the select is disabled and a lock line explains why |
lockMessage | string | 'Your role can view but not edit' | Lock line text when readOnly |
style | CSSProperties | — | Inline style of the root |
Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, onChange, onInput, disabled, name, value, autoComplete, multiple, plus className and event handlers on the root element.
Angular, Vue and HTML
Register the elements once (Angular guide), then use <co-select>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.
Angular template
<co-select label="…" placeholder="…" [options]="options" (co-change)="onChange($event.detail)"></co-select>
| Kind | Name | Description |
|---|---|---|
| attribute | label | Visible label; required |
| property / JSON attribute | options | Array<string | {value, label}>; required |
| attribute | placeholder | Text of a first empty option ("Choose one"); default none |
| attribute | size | 'sm' | 'md'; default 'md' |
| attribute | error | Error message (as TextField); default none |
| attribute | helper | Muted hint under the field (as TextField); default none |
| attribute | required | Red asterisk plus aria-required (as TextField); default false |
| attribute | read-only / readOnly | Read-only lock state: the select is disabled and a lock line explains why; default false |
| attribute | lock-message / lockMessage | Lock line text when readOnly; default 'Your role can view but not edit' |
| property / JSON attribute | style | Inline style of the root |
| attribute | default-checked / defaultChecked | |
| property / JSON attribute | default-value / defaultValue | |
| attribute | auto-focus / autoFocus | |
| attribute | disabled | |
| attribute | name | |
| property / JSON attribute | value | |
| attribute | auto-complete / autoComplete | |
| attribute | multiple | |
| event | co-change | (React: onChange) |
| event | co-input | (React: onInput) |