TextBox
Description
The TextBox component enables users to input text data in your application. It is designed for use in forms or any area where textual input is required. As part of the Components group, it provides a simple and uniform way to collect string inputs, with additional customization options for placeholders, read-only modes, password inputs, and styling.
Usage
To use the TextBox component, import the Tesserae UI library and instantiate it using the static helper method. The following sample demonstrates how to create basic TextBox instances including a standard, disabled, read-only, password, and required state.
API reference
public class TextBox : Input<TextBox>, ITextFormating, IHasBackgroundColor, IHasForegroundColor, IRoundedStyle, IDictationTargetA single-line text input component.
- Namespace
- Tesserae
- Inheritance
- Input<TextBox> → TextBox
- Implements
- ITextFormating, IHasBackgroundColor, IHasForegroundColor, IRoundedStyle, IDictationTarget
Constructors
| Name | Description |
|---|---|
| TextBox | Initializes a new instance of the TextBox class. |
Properties
| Name | Description |
|---|---|
| Placeholder | Gets or sets the placeholder text. |
| IsReadOnly | Gets or sets whether the text box is read-only. |
| MaxLength | Gets or sets the maximum length of the text. |
| IsPassword | Gets or sets whether the text box is in password mode. |
| Size | Gets or sets the text size. |
| Weight | Gets or sets the text weight. |
| TextAlign | Gets or sets the text alignment. |
| Background | Gets or sets the background color. |
| Foreground | Gets or sets the foreground color. |
| IsAI | Whether AI is on. |
| IsDictating | True while the microphone button is listening. |
| IsEditable | |
| CanDictate | |
| IsSpinning | Whether a SpinWhileAsync action is running. |
public string Placeholder { get ; set ; }Gets or sets the placeholder text.
public bool IsReadOnly { get ; set ; }Gets or sets whether the text box is read-only.
public int MaxLength { get ; set ; }Gets or sets the maximum length of the text.
public bool IsPassword { get ; set ; }Gets or sets whether the text box is in password mode.
public string Background { get ; set ; }Gets or sets the background color.
public string Foreground { get ; set ; }Gets or sets the foreground color.
Methods
| Name | Description |
|---|---|
| SetPlaceholder | Sets the placeholder text. |
| ReadOnly | Sets the text box as read-only. |
| Password | Sets the text box to password mode. |
Sets the text box input type to email. | |
| Name | Sets the name attribute on the underlying input. Password managers and browser autofill heuristics use this to identify the field's role (e.g. username, password, email) and to scope saved credentials to the current origin. |
| AutoComplete | Sets the autocomplete attribute on the underlying input. Use values from the WHATWG autofill spec (username, email, current-password, new-password, one-time-code, off, ...). Password managers rely on this hint to distinguish sign-in flows from password-creation flows. |
| NoBorder | Removes the border from the text box, in every state: no hover edge and no focus ring, for an input set inside a box that draws its own. |
| NoMinWidth | Removes the default minimum width. |
| UnlockHeight | Unlocks the height restriction. |
| AI | Marks the text box as holding what a model wrote - a generated title, a suggested value: the field takes the AI tint and an accent edge, and a spinner shown by SpinWhileAsync takes the AI arc. Turn it off again (AI(false)) when the value stops being the model's, e.g. once the user types over it. |
| WithDictation | Adds a microphone button at the end of the field, as an OmniBox has with DictationButton: pressing it dictates after the text already in the field, pressing it again stops, and what was heard stays. The words come from provider, else Provider, else the browser's speech recognition; the button is not shown when none is available. |
| DictationSource | Sets where this field's dictation gets its words from, instead of Provider, without adding the microphone button: for a field that is dictated into from elsewhere (see DictationTargets). |
| StartDictation | Starts dictating, as pressing the microphone button does. Does nothing when already dictating or when nothing can supply words, and works whether or not WithDictation was called. |
| StopDictation | Stops dictating; what was heard stays in the field. |
| GetDictation | The dictation of this field, made on first use so a field that never dictates carries none. |
| SpinWhileAsync | Shows a spinner inside the text box, at its end, while action runs - the text box's equivalent of OnClickSpinWhile. The spinner goes when the action ends, whether it finished or threw (the exception is not swallowed). Overlapping calls share one spinner, which stays until the last of them ends. The field stays editable meanwhile. |
public TextBox SetPlaceholder(string placeholder)Sets the placeholder text.
Parameters
- placeholder
- The placeholder text.
Returns
The current instance.
public TextBox Name(string name)Sets the name attribute on the underlying input. Password managers and browser autofill heuristics use this to identify the field's role (e.g. username, password, email) and to scope saved credentials to the current origin.
public TextBox AutoComplete(string value)Sets the autocomplete attribute on the underlying input. Use values from the WHATWG autofill spec (username, email, current-password, new-password, one-time-code, off, ...). Password managers rely on this hint to distinguish sign-in flows from password-creation flows.
public TextBox NoBorder()Removes the border from the text box, in every state: no hover edge and no focus ring, for an input set inside a box that draws its own.
public TextBox AI(bool value = true, bool strongEffect = false)Marks the text box as holding what a model wrote - a generated title, a suggested value: the field takes the AI tint and an accent edge, and a spinner shown by SpinWhileAsync takes the AI arc. Turn it off again (AI(false)) when the value stops being the model's, e.g. once the user types over it.
Parameters
- value
- Whether the AI look is on.
- strongEffect
- Asks for the louder form of the AI styling (
tss-ai-strong); see the ai-variants reference.
public TextBox WithDictation(DictationProvider provider = null)Adds a microphone button at the end of the field, as an OmniBox has with DictationButton: pressing it dictates after the text already in the field, pressing it again stops, and what was heard stays. The words come from provider, else Provider, else the browser's speech recognition; the button is not shown when none is available.
Parameters
- provider
- The source of this field's dictation, instead of the application-wide one.
public TextBox DictationSource(DictationProvider provider)Sets where this field's dictation gets its words from, instead of Provider, without adding the microphone button: for a field that is dictated into from elsewhere (see DictationTargets).
public TextBox StartDictation()Starts dictating, as pressing the microphone button does. Does nothing when already dictating or when nothing can supply words, and works whether or not WithDictation was called.
public TextBox StopDictation()Stops dictating; what was heard stays in the field.
private DictationController GetDictation()The dictation of this field, made on first use so a field that never dictates carries none.
| Overload | |
|---|---|
| SpinWhileAsync(Func<Task>) | Shows a spinner inside the text box, at its end, while action runs - the text box's equivalent of OnClickSpinWhile. The spinner goes when the action ends, whether it finished or threw (the exception is not swallowed). Overlapping calls share one spinner, which stays until the last of them ends. The field stays editable meanwhile. |
| SpinWhileAsync<T>(Func<Task<T>>) | SpinWhileAsync for an action with a result, which is handed back. |
SpinWhileAsync(Func<Task>)
public async Task SpinWhileAsync(Func<Task> action)Shows a spinner inside the text box, at its end, while action runs - the text box's equivalent of OnClickSpinWhile. The spinner goes when the action ends, whether it finished or threw (the exception is not swallowed). Overlapping calls share one spinner, which stays until the last of them ends. The field stays editable meanwhile.
Parameters
- action Func<Task>
Samples
Basic and Customized TextBox Examples
The following sample demonstrates creating multiple TextBox variations including standard, disabled, read-only, password input, required state, error messaging, placeholder text, and validation options.