Components · engine.select · version 0.4.0
Select
Chooses one option from a list that opens below a button. Takes part in forms like a native select.
Preview
Every variant in every state, drawn by the same definition that the Figma sync and the tests use.
| Component | rest | disabled | invalid | invalid, disabled | open | open, invalid | focus | focus, invalid | focus, open | focus, open, invalid | hover | hover, invalid | hover, open | hover, open, invalid | hover, focus | hover, focus, invalid | hover, focus, open | hover, focus, open, invalid |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| select | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry | Apple Banana Cherry |
Install
npm install @uiuxengine/reactComponents come from npm and stay identical to their definition and their Figma component. See Installation.
Usage
import { Select } from "@uiuxengine/react";
export function Example() {
return (
<Select placeholder="Choose an option" accessibleLabel="Select" />
);
}Guidelines
- Use for choosing one of several known options. For two options, consider a switch or radio buttons.
- Name every select: put it in a field, or use accessibleLabel or a label element that points at its id. In a spec, a field or accessibleLabel names it.
- The placeholder says what to choose, for example 'Choose a region'. It isn't a label.
- Set invalid while the host shows a validation message for it. The select doesn't set it by itself.
- Keep options short. Long lists scroll; a select is not a search field.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
accessibleLabel | text, up to 160 | — | Accessible name, when no label element names the select. |
placeholder | text, up to 80 | — | Shown while no option is selected. |
name | text, up to 120 | — | The field name the value is submitted as. |
required | boolean | false | A form can't be submitted empty. |
disabled | boolean | false | Prevents interaction. |
invalid | boolean | false | Marks the value as invalid, while the host shows why. |
Slots
| Slot | Takes | Description |
|---|---|---|
options | list of engine.option | The options, in order. |
Events
valueChange- A person or an authorized agent chose an option, or a form reset the select.
openChange- The list was opened or closed.
Accessibility
- Renders a native <div> with the role
generic. - The value must be the value of one of the options.
As a spec
Agents describe interfaces as JSON specs. A spec renders only after it validates against the installed contracts, the approved icons and the host's actions. Edit it to see.
Apple
Banana
Cherry
No actions yet.
JSON Schema of the props
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "urn:uiuxengine:component:engine.select@0.4.0",
"title": "select",
"description": "Chooses one option from a list that opens below a button. Takes part in forms like a native select.",
"type": "object",
"properties": {
"accessibleLabel": {
"description": "Accessible name, when no label element names the select.",
"type": "string",
"maxLength": 160
},
"placeholder": {
"description": "Shown while no option is selected.",
"type": "string",
"maxLength": 80
},
"name": {
"description": "The field name the value is submitted as.",
"type": "string",
"maxLength": 120
},
"required": {
"description": "A form can't be submitted empty.",
"type": "boolean",
"default": false
},
"disabled": {
"description": "Prevents interaction.",
"type": "boolean",
"default": false
},
"invalid": {
"description": "Marks the value as invalid, while the host shows why.",
"type": "boolean",
"default": false
},
"options": {
"description": "The options, in order.",
"type": "array",
"items": {
"type": "object",
"properties": {
"component": {
"enum": [
"engine.option"
]
},
"props": {
"type": "object"
}
},
"required": [
"component"
],
"additionalProperties": false
},
"minItems": 1
}
},
"required": [
"options"
],
"additionalProperties": false,
"$defs": {
"iconRef": {
"type": "object",
"description": "A reference to an icon in the host's approved catalog.",
"properties": {
"type": {
"const": "icon"
},
"id": {
"type": "string",
"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
},
"style": {
"type": "string",
"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
},
"weight": {
"type": "string",
"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
}
},
"required": [
"type",
"id"
],
"additionalProperties": false
}
}
}