UI Toolbox logoUI Toolbox

InputGroup

An InputGroup puts one border around a text field and its addons: an icon, a short text such as a unit or a prefix, a Kbd, or a button.

Four input groups: a name with a prefix and a suffix, a number with a unit, a text field with a Join button, and a text field with a clear button

How to add an input group:

<tb:InputGroup show-clear-button="true">
    <ui:VisualElement name="searchIcon" class="tb-input-group__icon" />
    <ui:TextField placeholder-text="Search..." />
    <tb:Kbd keys="Ctrl+K" />
</tb:InputGroup>

<tb:InputGroup name="site">
    <ui:Label text="https://" />
    <ui:TextField />
    <ui:Button text="Open" name="open" />
</tb:InputGroup>
var group = new InputGroup { ShowClearButton = true };
group.Add(new TextField());
group.Add(new Label("kg"));

root.Q("searchIcon").style.backgroundImage = searchIcon;
root.Q<Button>("open").clicked += () => Application.OpenURL("https://" + root.Q<InputGroup>("site").Field.value);
Member Description
The children The field and the addons. They show in a row, in their order: a child before the field is at the start, a child after it is at the end.
ShowClearButton (show-clear-button) Shows a "×" button at the end while the field has text.
Field The first field with a text value in the group: a TextField, a ComboBox, a SearchDropdown. Null when there is none.
ClearText() Empties Field, with a change event, and gives it the focus. The clear button calls it.

The addons:

Child Look
A Label A text addon in the muted text color.
An Image, or an element with the class tb-input-group__icon An icon of 16 x 16 px with the muted text color as its tint. Set the image of the element in code or in USS.
A Kbd A key hint.
A Button A button as high as the group, with no border of its own.

Tips:

Styling

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

Class Element
tb-input-group The group: a row with a border and --tb-color-background.
tb-input-group--focused Set while the field has the focus. The border is --tb-color-accent.
tb-input-group__content The row of the field and the addons.
tb-input-group__icon Add it to an element that shows an icon.
tb-input-group__clear The clear button.

To make a text addon look like a separate part:

.tb-input-group > .unity-label {
    background-color: var(--tb-color-surface-alt);
}

In a selector, the field and the addons are children of tb-input-group. A selector with tb-input-group__content > in front of them does not match.