UI Toolbox logoUI Toolbox
Support

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.

A Bag card with a search box that has a magnifier icon and a Ctrl + F key hint, above a list of items with countsA Bag card with a search box that has a magnifier icon and a Ctrl + F key hint, above a list of items with counts

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.
ClearOnEscape (clear-on-escape) Escape empties the field while the clear button shows and the field has text, and the screen does not see that key. An open list of the field closes first. Default true.
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.
Watermark Any element that lies over the empty text box, such as an icon with a name. See Watermark.
HideWatermarkOnFocus (hide-watermark-on-focus) Hides the watermark while the field has the focus. Default false.

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:

Watermark

A watermark is any element that lies over the text box while the field is empty and goes away as soon as there is text. It is more than a placeholder: it can be an icon with a name, a spinning coin or a whole row.

<tb:InputGroup hide-watermark-on-focus="true">
    <ui:TextField />
    <ui:VisualElement class="tb-input-group__watermark">
        <tb:MediaIcon kind="Note" />
        <ui:Label text="Name your song" />
    </ui:VisualElement>
</tb:InputGroup>
var group = new InputGroup();
group.Add(new TextField());
var row = new VisualElement();
row.Add(new MediaIcon(MediaIconKind.Note));
row.Add(new Label("Name your song"));
group.Watermark = row;

// Any TextField takes a watermark, with no group
var field = new TextField();
Watermark.Attach(field, new Label("Name"), hideOnFocus: true);

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.
tb-input-group__watermark Add it to a child in UXML that becomes the watermark.
tb-watermark The box over the text box that holds the watermark.
tb-watermarked Set on a text field that has a watermark.
tb-watermarked--shown Set while the watermark shows.

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.

The InputGroupDemo scene shows a search field of the bag with a key hint, an amount of gold for a bid, a server address with a port, watermarks with an icon and with a spinning coin, and the addons and the states of the group.