UI Toolbox logoUI Toolbox
Support

ComboBox

A ComboBox is a text field with an arrow button that shows a list of choices. Typed text filters the list. The value is the text: a choice, or with allow-free-text (the default) any text.

A Class box open on a list of six classes, with Mage selectedA Class box open on a list of six classes, with Mage selected

<UIToolbox.ComboBox label="Size" placeholder="Type or pick a size"
    choices="Small,Medium,Large,Extra Large" />
<UIToolbox.ComboBox
    label="Quality"
    choices="Low,Medium,High,Ultra"
    allow-free-text="false" />
<UIToolbox.ComboBox
    label="Difficulty"
    choices="Easy,Normal,Hard"
    editable="false" />
var font = new ComboBox("Font")
{
    Items = new List<ChoiceItem>
    {
        new("Arial", "Sans", group: "Sans serif"),
        new("Georgia", "Serif", group: "Serif"),
        new("Courier", "Mono", group: "Monospace", enabled: false)
    }
};
font.value = "Georgia";
font.RegisterValueChangedCallback(evt =>
    Debug.Log($"{evt.newValue} ({font.SelectedIndex})"));
Member Description
value The text. A ChangeEvent<string> comes at a pick, at Enter and when the focus leaves the field, not at each typed letter.
Items The ChoiceItems in the list: icon, detail, group and enabled state, as in SearchDropdown.
Choices (choices) The texts of Items. A set replaces Items with plain items.
AllowFreeText (allow-free-text) The value can be text that is not a choice (true). When false, other text goes back to the value, and a typed choice name in any case picks that choice.
Editable (editable) The user can type in the field (true). When false, the field is a button for the list: see below.
Placeholder (placeholder) Text in the empty field.
SelectedIndex, SelectedItem The choice that is the value, or -1 and null for other text. Setting -1 clears the value.
GroupOf, MakeItem, BindItem Group headers and custom rows, as in SearchDropdown.
IsOpen, Open(), Close(), Toggle(), FilteredItems The popup state and the choices it shows.

A combo box that takes no typing

Set editable="false" for a field that only picks from the list.

Which field to use

Field Use it when
Unity DropdownField The list is short and has plain texts. Its menu is Unity's own; in a workspace it takes the theme colors.
ComboBox with editable="false" The list is fixed, and the rows need an icon, a detail text, a group or a disabled state, or the list must look like the other toolbox lists.
ComboBox (editable) The list is long and the user filters it by typing, or the value can be a new text.

For a search in a very long list, or for more than one choice, use a SearchDropdown.

Shared parts

Styling

The rules are in Assets/UIToolbox/Runtime/Resources/UIToolbox/Styles/Controls.uss.

Class Element
tb-combo-box The field. Its input is one box, a row with the text field and the arrow: the box draws the border and the background, so the hover border, the focus ring and the error border go around both parts. In an InputGroup, the group draws the border.
tb-combo-box--focused The text has the focus. The border of the box is --tb-color-accent.
tb-combo-box--not-editable A field with Editable off, with the look of a DropdownField: the arrow is in the box, the caret and the selection are see-through, and a hover anywhere on the box colors the text and the arrow together.
tb-combo-box__text The text field. It takes the free width, with no border and no background of its own.
tb-combo-box__arrow The arrow button on the right: 18 px wide, with no border and no background of its own. The arrow is --tb-color-text-muted, and --tb-color-text while the pointer is on the box.
tb-combo-box__popup The list under the field, with tb-choice-list (see SearchDropdown). It has the width of the field.

A disabled ComboBox takes no focus, no typing and no click on the arrow. The box has no fill, and the label, the text and the arrow have --tb-color-text-disabled. See Disabled state.

The ComboBoxDemo scene shows the name of a mount with the defaults, a screen resolution that takes no typing, server regions in groups with rows that show the ping, and the looks of the field, with a game look that the open list takes too.