tuix-dropdown

A select built on tuix-input, with an optional type-to-filter mode.

tuix-dropdown wraps a tuix-input with a list of options. In single mode the field is read-only and clicking it opens the list; in search mode typing filters the options.

Loading the components…

The list is set as a property. The attribute exists and parses JSON, so options='["Draft", "Sent"]' works for a short list of plain values, but anything longer belongs in the property:

const dropdown = document.querySelector('tuix-dropdown')
 
dropdown.options = [
    { name: 'Switzerland', value: 'CH' },
    { name: 'Germany', value: 'DE' },
]
dropdown.value = dropdown.options[0]
 
dropdown.addEventListener('select', (event) => console.log(event.detail.value)) // 'CH'

Types

Single

The default. The field cannot be typed in; the whole field is the trigger.

Loading the components…

Options may be plain values, as here, in which case the label is the value.

Typing filters the list, and blurring restores the label of the selected option.

Loading the components…

Description states

The helper line is the input's, so the same five description states apply.

Loading the components…

Option types

type TuixDropdownPlainOption = string | number | boolean
 
interface TuixDropdownObjectOption {
    name: string // shown in the list
    value: TuixDropdownPlainOption // reported by the select event
}
 
type TuixDropdownOption = TuixDropdownPlainOption | TuixDropdownObjectOption

Keyboard

KeyEffect
Enter on the fieldOpens or closes the list
ArrowDown / ArrowUpMoves through the options
Enter on an optionSelects it
EscapeCloses the list

Clicking anywhere outside the component also closes the list.

API

Properties

PropertyAttributeTypeDefaultDescription
optionsoptionsTuixDropdownOption[][]The list. Property, or JSON in the attribute
valuevalueTuixDropdownOptionNoneThe selected option. Property, or JSON
typetypeDropdownTypesinglesingle or search
titletitlestring''Floating label
placeholderplaceholderstring''Placeholder text
descriptiondescriptionstringNoneHelper text under the field
descriptionTypedescriptiontypeDescriptionTypetextHelper line state
disableddisabledbooleanfalseBlocks opening the list
darkdarkbooleanfalseDark palette

Events

EventDetailWhen
select{ value: TuixDropdownPlainOption }An option is chosen by click or Enter
input-single{ value: string }The user types, in search mode

The detail of select is the option's value, never the object. Typed as CustomEventTuixDropdownSelect and CustomEventTuixDropdownInput.

Notes

  • Assigning a new options array clears the current selection; set value again afterwards if it should survive.
  • The list is absolutely positioned inside the component, so the dropdown needs room below it, or the page has to scroll.

On this page