Skip to content

Select

Select components are Input Fields that allow users to pick a single item from a predefined list of options. They use the native HTML <select> element to provide familiar interaction patterns, especially on mobile devices.

select.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'select',
path: 'country',
label: 'Country',
props: {
options: [
{
label: 'United States',
value: 'us',
},
{
label: 'Canada',
value: 'ca',
},
{
label: 'Mexico',
value: 'mx',
},
],
},
},
],
});
select.json
{
"form": [
{
"uid": "",
"kind": "input",
"type": "select",
"path": "country",
"label": "Country",
"props": {
"options": [
{ "label": "United States", "value": "us" },
{ "label": "Canada", "value": "ca" },
{ "label": "Mexico", "value": "mx" }
]
}
}
]
}

Use these props to customize your Select component.

proptypedescription
optionsarrayRequired. Array of objects representing the dropdown choices
placeholderstringText shown when no option is selected. Defaults to “Select an option”
hintstringA description to display below the select dropdown
iconstringCustom icon class to display inside the select box (e.g. fas fa-globe)
labelFieldstringWhich object key to use as the display label for an option. Defaults to label
valueFieldstringWhich object key to use as the underlying value for an option. Defaults to value
autocompletestring'on', 'off', or a space-separated list of W3C autofill tokens

Use the property placeholder to define the default empty-state text.

select.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'select',
path: 'country',
label: 'Country',
props: {
placeholder: 'Select your country',
options: [
{
label: 'United States',
value: 'us',
},
{
label: 'Canada',
value: 'ca',
},
],
},
},
],
});
select.json
{
"form": [
{
"uid": "",
"kind": "input",
"type": "select",
"path": "country",
"label": "Country",
"props": {
"placeholder": "Select your country",
"options": [
{ "label": "United States", "value": "us" },
{ "label": "Canada", "value": "ca" }
]
}
}
]
}

Use the property hint to add descriptive text or validation instructions.

select.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'select',
path: 'country',
label: 'Country',
props: {
hint: 'Please select your current country of residence.',
options: [
{
label: 'United States',
value: 'us',
},
],
},
},
],
});
select.json
{
"form": [
{
"uid": "",
"kind": "input",
"type": "select",
"path": "country",
"label": "Country",
"props": {
"hint": "Please select your current country of residence.",
"options": [
{ "label": "United States", "value": "us" }
]
}
}
]
}

Use the property icon to add a visual indicator inside the select input, on the left side.

select.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'select',
path: 'country',
label: 'Country',
props: {
icon: 'fas fa-globe',
options: [
{
label: 'United States',
value: 'us',
},
],
},
},
],
});
select.json
{
"form": [
{
"uid": "",
"kind": "input",
"type": "select",
"path": "country",
"label": "Country",
"props": {
"icon": "fas fa-globe",
"options": [
{ "label": "United States", "value": "us" }
]
}
}
]
}

If your data source uses different keys for the label and value (e.g., name and code), use labelField and valueField to map them accordingly.

select.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'select',
path: 'country',
label: 'Country',
props: {
labelField: 'name',
valueField: 'code',
options: [
{
name: 'United States',
code: 'us',
},
{
name: 'Canada',
code: 'ca',
},
],
},
},
],
});
select.json
{
"form": [
{
"uid": "",
"kind": "input",
"type": "select",
"path": "country",
"label": "Country",
"props": {
"labelField": "name",
"valueField": "code",
"options": [
{ "name": "United States", "code": "us" },
{ "name": "Canada", "code": "ca" }
]
}
}
]
}

Select components can be styled as explained in the Styling Guide.

Following you will find a list with the CSS Variables and a quick description of what you will style.

CSS VariableDescription
--gui-text-defaultDropdown arrow indicator color
--gui-space-gap--innerLabel gap
--gui-intent-errorBorder and focus shadow color when invalid

This is the anatomy of the Select Component in case you want to use your CSS styles.

select-anatomy.html
<gui-select>
<label for="fieldUid">
Label
<div class="gui-select__hint" id="fieldUid_hint">Hint</div>
</label>
<div class="gui-widget">
<select
id="fieldUid"
class="gui-select-input gui-select--icon"
aria-required="true"
aria-describedby="fieldUid_hint"
>
<option value="" disabled selected>
Select an option
</option>
<option value="us">United States</option>
<option value="ca">Canada</option>
</select>
<span class="gui-widget-icon fas fa-globe"></span>
</div>
</gui-select>