UI Toolbox logoUI Toolbox
Support

SearchField

A SearchField is a text field for searching: a magnifier that stays while the player types, a "Search" placeholder in the language of the player, a clear button, and a search event that waits until the player stops typing. It is an InputGroup with all of that set up, so you add icons or a Kbd the same way. The search box of the EmojiPicker, the FileBrowser, the PropertyGrid, the LogView and the CommandPalette is a SearchField.

A bag search with a magnifier and the placeholder Search, a search box with the text potion and a clear button, and a text box with an icon and a name as a watermarkA bag search with a magnifier and the placeholder Search, a search box with the text potion and a clear button, and a text box with an icon and a name as a watermark

How to add a search field:

<tb:SearchField name="search" placeholder="Search the bag" />

<tb:SearchField delay="0" show-icon="false" clear-on-escape="false">
    <tb:Kbd keys="Ctrl+F" />
</tb:SearchField>
var search = new SearchField { Delay = 300 };
root.Add(search);

// Runs 300 ms after the last key, and at once for an empty text
search.SearchChanged += text => list.Filter(text);

// Runs when the player presses Enter, after the pending search
search.Submitted += text => list.OpenFirst(text);

// A custom placeholder, and a hint for a shortcut
search.Placeholder = "Search the bag";
search.Add(new Kbd { Keys = "Ctrl+F" });

SearchField settings

Member Description
value The text. A set shows it in the box and sends a change event. SetValueWithoutNotify sets it and sends no event.
Placeholder (placeholder) The text of the empty box. By default it is "Search", and it follows the language of the player. Set it to your own text, or to null for the default.
Delay (delay) The wait in milliseconds between the last change of the text and SearchChanged. Default 200. With 0 each change sends its event at once. An empty text always searches at once.
ShowIcon (show-icon) Shows the magnifier in front of the box. Default true.
ClearOnEscape (clear-on-escape) Escape empties a box that has text, and the screen does not see that key. With no text, Escape goes on to the screen. Default true.
Icon The element in front of the box. A set replaces the magnifier; null takes it away.
TextField The text field inside, for the focus and the text edition.
SearchChanged An event with the text, after Delay.
Submitted An event with the text when the player presses Enter. A search that waits runs first.
show-clear-button The clear button, from InputGroup. It is on by default for a search field.
Watermark (hide-watermark-on-focus) From InputGroup: any element over the empty box, as in InputGroup.

Tips:

Styling

The rules are in Assets/UIToolbox/Runtime/Resources/UIToolbox/Styles/Controls.uss. A SearchField has the classes of an InputGroup too.

Class Element
tb-search-field The group.
tb-search-field__icon The magnifier. Its color is --tb-color-text-muted.
tb-search-field__text The text field.

The InputGroupDemo scene shows a search field that filters a bag, with a key hint and the options of the field.