Skip to content

Combo Box - Single Select

<tpg-combo-box></tpg-combo-box>

Combo box elicits a multi-level list of drop-down choices that can contain values ot itemized options. When the dropdown is empty, the ComboBox will be set to “disabled” with N/A as its content.

Examples

The Combo Box also has the same properties/attributes as Text Field. You can check the Text Field page for its available attributes.

Basic Usage

Pass as many options into the Combo Box as you want.

When more than 10 options are put into the combo-box, the dropdown menu will automatically become scrollable. The amount of rendered items is determined by maxRenderedOptions prop.

The combobox is also searchable, and has keyboard navigation.

Default value

Use the selected-value attribute on the Combo Box to set a default selected value. The value has to correspond with the value of a Menu Item.

Icons

You can use the leading-icon-template attribute to set icon on both the Combo Box and the individual Menu Items.

If a selected Menu Item has a icon it will automatically override any that is set in the Combo Box.

Clear

You can use the clear-button attribute to easily clear the input of Combo Box

Full width

The Combo Box’s dropdown menu will by default scale to the width of its largest Menu Item. This behavior can be changed by including the full-width attribute, which causes it to scale with the width of the Combo Box itself.

Event handling

The Combo Box is a controlled component, which means its selection state must be managed externally by your application logic.

When a Menu Item is selected, the component dispatches a tpg-change event. To update the selected value, listen for this event and set the Combo Box’s selectedValue property manually based on the event’s payload.

Tables

Properties

Attribute Property Description Type Default Value
options options Array of objects containing items to be listed ComboBoxOption<unknown>[] []
max-rendered-options maxRenderedOptions Limits how many options are rendered number 100
custom-render-menu-item customRenderMenuItem Custom render method (option: FuzzyOption<unknown>) => TemplateResult | undefined | undefined
selected-value selectedValue Value of the currently selected menu item. Can be used to preselect a Menu Item should their values match. string ''
label label Label of the textfield. string ''
value value The default value on the textfield string ''
message message Message to appear on badge if set. string ''
placeholder placeholder Optional placeholder that is visible if value is empty string ''
type type The type of textfield to render in terms of severity-level. 'default' | 'error' | 'warning' | 'danger' 'default'
clear-button clearButton Flag that includes a button to clear the text if included. boolean false
full-width fullWidth Determines if the dropdown menu scales to its parent (text-field) or if it scales to its largest menu item.. boolean false
disabled disabled Whether or not the combobox is disabled boolean false
read-only readOnly Whether or not the combobox is read only boolean false
leading-icon-template leadingIconTemplate URI-encoded SVG template for the button's icon. Supported constants are found in IconConstant | '' ''
should-sort shouldSort Whether the list should get sorted while searching. boolean true
form-associated formAssociated boolean true
name name name property for use in conjunction with html forms string

Events

Event name Reactjs attribute Description
tpg-change ontpg-change Emitted when an item is selected, containing the value identifier of this item.

Functions

Name Description Arguments
No functions found.

Slots

Name Description
No slots found.

CSS Parts

Attribute Description
No CSS parts found.

Sandbox