Class TextField
A text input component that allows users to enter and edit text.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class TextField : ExVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<string>, IValidatableElement<string>, INotifyValueChanging<string>, INotifyValueChanged<string>
Remarks
TextField is a fundamental input component that enables users to enter and edit text content. It provides a versatile interface for capturing user input in various formats like plain text, passwords, and validated content.
The component supports different sizes, placeholder text, leading and trailing icons, and various customization options to fit different use cases and design requirements.
When using TextField for sensitive information like passwords, make sure to enable the isPassword property to mask the input appropriately.
Examples
Basic TextField Example: Simple text input with placeholder.
<TextField placeholder="Enter your name" size="Size.M" />
Password Field Example: Secure password input with validation.
<TextField
isPassword="true"
maskChar="*"
placeholder="Enter password"
maxLength="20"
leadingIconName="lock"
/>
Search Field Example: Search input with icons.
<TextField
leadingIconName="search"
trailingIconName="clear"
placeholder="Search..."
size="Size.L"
/>
Validated Input Example: Email input with validation.
var textField = new TextField();
textField.placeholder = "Enter email";
textField.validateValue = (value) => {
return value.Contains("@") && value.Contains(".");
};
Constructors
TextField()
Default constructor.
Declaration
public TextField()
TextField(string)
Construct a TextField with a predefined text value.
Declaration
public TextField(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | A default text value. |
Remarks
No event will be triggered when setting the text value during construction.
Fields
inputContainerUssClassName
The TextField input container styling class.
Declaration
public const string inputContainerUssClassName = "appui-textfield__inputcontainer"
Field Value
| Type | Description |
|---|---|
| string |
inputUssClassName
The TextField input styling class.
Declaration
public const string inputUssClassName = "appui-textfield__input"
Field Value
| Type | Description |
|---|---|
| string |
leadingContainerUssClassName
The TextField leading container styling class.
Declaration
public const string leadingContainerUssClassName = "appui-textfield__leadingcontainer"
Field Value
| Type | Description |
|---|---|
| string |
leadingIconUssClassName
The TextField leading icon styling class.
Declaration
public const string leadingIconUssClassName = "appui-textfield__leadingicon"
Field Value
| Type | Description |
|---|---|
| string |
placeholderUssClassName
The TextField placeholder styling class.
Declaration
public const string placeholderUssClassName = "appui-textfield__placeholder"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The TextField size styling class.
Declaration
public const string sizeUssClassName = "appui-textfield--size-"
Field Value
| Type | Description |
|---|---|
| string |
trailingContainerUssClassName
The TextField trailing container styling class.
Declaration
public const string trailingContainerUssClassName = "appui-textfield__trailingcontainer"
Field Value
| Type | Description |
|---|---|
| string |
trailingIconUssClassName
The TextField trailing icon styling class.
Declaration
public const string trailingIconUssClassName = "appui-textfield__trailingicon"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The TextField main styling class.
Declaration
public const string ussClassName = "appui-textfield"
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The content container of the TextField.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
invalid
The invalid state of the TextField.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
isPassword
Whether the TextField is a password field.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool isPassword { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
isReadOnly
Whether the TextField is read-only.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool isReadOnly { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
leadingElement
The TextField leading element.
Declaration
public VisualElement leadingElement { get; set; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
leadingIconName
The leading icon name.
Declaration
[CreateProperty]
[UxmlAttribute]
public string leadingIconName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
maskChar
The TextField mask character.
Declaration
[CreateProperty]
[UxmlAttribute]
public char maskChar { get; set; }
Property Value
| Type | Description |
|---|---|
| char |
maxLength
The TextField max length.
Declaration
[CreateProperty]
[UxmlAttribute]
public int maxLength { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
placeholder
The TextField placeholder text.
Declaration
[CreateProperty]
[UxmlAttribute]
public string placeholder { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
size
The TextField size.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
trailingElement
The TextField trailing element.
Declaration
public VisualElement trailingElement { get; set; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
trailingIconName
The trailing icon name.
Declaration
[CreateProperty]
[UxmlAttribute]
public string trailingIconName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
validateValue
The validation function for the TextField.
Declaration
[CreateProperty]
public Func<string, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<string, bool> |
value
The TextField value.
Declaration
[CreateProperty]
[UxmlAttribute]
public string value { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
SetValueWithoutNotify(string)
Set the TextField value without notifying the change.
Declaration
public void SetValueWithoutNotify(string newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | newValue | The new value of the TextField. |