Skip to content

Dropdown

Dropdown components are Input Fields that provide a searchable list of items. Users can either type in the input to filter the list or select an item directly from the interactive dropdown menu.

dropdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'dropdown_id',
kind: 'input',
type: 'dropdown',
path: 'selection',
label: 'Select an Item',
props: {
items: [
{
template: 'Apple',
value: 'apple',
},
{
template: 'Banana',
value: 'banana',
},
{
template: 'Cherry',
value: 'cherry',
},
],
placeholder: 'Type to search...',
},
},
],
});

Use these props to customize your Dropdown component.

proptypedescription
itemsarrayRequired. Array of items to be displayed in the dropdown list
placeholderstringText shown in the input when it is empty
hintstringA description to display below the input
labelFieldstringField to use for the display label when items are objects
valueFieldstringField to use for the value when items are objects
searchFieldsarrayList of fields to search on when filtering the list
heightnumberHeight of the dropdown list container
itemHeightnumberHeight of each individual item in the list
inputDebouncenumberDelay in milliseconds before triggering a search/filter
autocompletestring'on', 'off', or a space-separated list of W3C autofill tokens

Use the property hint to provide instructions for the user.

dropdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'dropdown_hint',
kind: 'input',
type: 'dropdown',
path: 'selection',
label: 'Select an Item',
props: {
items: [
{
template: 'Apple',
value: 'apple',
},
{
template: 'Banana',
value: 'banana',
},
],
hint: 'Start typing to filter the available items',
},
},
],
});

If your items are complex objects, you can specify which fields to use for labels, values, and searching.

dropdown.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'dropdown_custom',
kind: 'input',
type: 'dropdown',
path: 'selection',
label: 'Custom Fields',
props: {
items: [
{
template: {
name: 'USA',
code: 'US',
},
value: 'us',
},
{
template: {
name: 'Canada',
code: 'CA',
},
value: 'ca',
},
],
labelField: 'name',
valueField: 'code',
searchFields: ['name', 'code'],
},
},
],
});

Dropdowns can be styled as explained in the Styling Guide.

Dropdowns leverage standard container and list variables.

CSS VariableDescription
--gui-radius-mdBorder radius for the container
--gui-border-defaultDefault border color

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

dropdown-anatomy.html
<div class="gui-dropdown">
<gui-label>
<label for="dropdown_id">Select an Item</label>
<div class="gui-label__hint">Type to search...</div>
</gui-label>
<div class="gui-widget">
<input type="text" id="dropdown_id" placeholder="Type to search..." />
<gui-list>
<div class="gui-list__container">
<div class="gui-list__item-wrapper" role="option" aria-selected="false">
<div class="gui-list-item">Apple</div>
</div>
<div class="gui-list__item-wrapper" role="option" aria-selected="false">
<div class="gui-list-item">Banana</div>
</div>
</div>
</gui-list>
</div>
</div>