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.


<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. |
- The arrow button and F4 open the list with every choice and the value highlighted. Alt+Down also opens it.
- Typing opens the list and filters it by substring. Up and Down move the highlight, Enter picks it, and Escape drops the typed text.
- While the list is closed, Up and Down on the arrow keys step the value to the previous or next enabled choice. The D-pad and the left stick of a gamepad move the focus on instead, so a player never gets stuck in the field and never changes the value by passing it.
- The gamepad submit button opens the list and picks the highlighted choice. The cancel button closes it with no change. The D-pad moves the highlight while the list is open.
- The popup is a
ChoiceListwith the width of the field.
A combo box that takes no typing
Set editable="false" for a field that only picks from the list.
- A click anywhere on the field opens the list. A second click closes it.
- The field shows no caret, and the text cannot be changed or selected with the mouse.
- Enter, Space, F4, Alt+Down and the gamepad submit button open the list. Up and Down on the arrow keys step the value while the list is closed.
- A typed letter goes to the next enabled choice that starts with it. The same letter again goes to the next one. While the list is closed, this sets the value; while it is open, it moves the highlight.
- The value is always a choice, or the text that your code set.
AllowFreeTexthas no effect.
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
ShowClearButton(show-clear-button) adds the shared ClearButton between the text and the arrow while the field has text. A click empties the value, sends a change event and keeps the focus. Default false.- Escape closes an open list first. Then, with the clear button on, it clears the text. After that it goes on to the screen.
- The d-pad never clears the text and never closes the list. With the list open it only moves the highlight; the submit button picks.
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.