SearchBox
Description
SearchBox provides a dedicated input field for searching through content. It is designed to capture search queries either when the user presses "Enter" or automatically as they type. Being a part of the Components group, it offers customization options such as underlining, custom icons, disabled states, and more. Use the SearchBox when you need an interactive search input that supports user-triggered search events.
Usage
To instantiate a SearchBox, use the static helper method from Tesserae.UI. You can chain various methods to configure its appearance and behavior, including setting placeholder text, enabling a "search as you type" mode, customizing the icon, and handling the search event.
Below is a simple example demonstrating how to create a SearchBox:
API reference
public class SearchBox : ComponentBase<SearchBox, HTMLInputElement>, ITextFormating, IHasBackgroundColor, ITabIndex, IRoundedStyleA single-line search input with a leading magnifier glyph, a trailing clear button and search-on-enter / debounced-input semantics.
Constructors
Properties
public int TabIndex { set ; }Sets the keyboard tab order of the component.
public bool IsFocusedReturns a value indicating whether the component is focused.
public bool IsEnabled { get ; set ; }Gets or sets a value indicating whether the component is interactive (enabled).
public bool IsUnderlined { get ; set ; }Returns a value indicating whether the component is underlined.
public string Text { get ; set ; }Gets or sets the text shown in the component.
public string Placeholder { get ; set ; }Gets or sets the placeholder text shown when the component is empty.
public bool IsInvalid { get ; set ; }Gets or sets a value indicating whether the component is currently in an invalid state.
public TextWeight Weight { get ; set ; }Gets or sets the font weight of the component.
public TextAlign TextAlign { get ; set ; }Gets or sets the text alignment of the component.
Methods
public override HTMLElement Render()Renders the component's root HTML element.
public void Attach(ComponentEventHandler<SearchBox> handler)Attaches a handler to the component's value-changed event.
public SearchBox SetPlaceholder(string error)Sets the placeholder of the component.
public SearchBox NotUnderlined()Removes the underline from the component.
public SearchBox SearchAsYouType()Configures the search box to fire its callback after every keystroke (debounced) rather than only on submit.
public SearchBox OnSearch(SearchEventHandler onSearch)Registers a callback invoked when the search event fires.
public SearchBox SetKeyboardShortcut(params string[] keys)Registers a global keyboard shortcut that focuses this SearchBox when pressed, and renders a visual chip showing the shortcut on the right side of the box. Modifier names are case-insensitive ("Ctrl", "Cmd", "Meta", "Alt", "Shift"). Example: .
public SearchBox Height(UnitSize unitSize)Gets or sets the CSS height of the component.
Samples
Basic SearchBox with Underline and Search-as-You-Type
The following sample demonstrates the creation of a SearchBox that is underlined, triggers search events automatically as the user types, and displays an alert with the search query.
See also
- TextBox – The basic text input component that forms the foundation of the SearchBox.
- Button – Often used in conjunction with search inputs for initiating search actions manually.