Class TextArea
A multi-line text input field that allows users to enter and edit longer text content.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class TextArea : ExVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<string>, IValidatableElement<string>, INotifyValueChanging<string>, INotifyValueChanged<string>
Remarks
TextArea is a versatile input component that enables users to enter and edit multiple lines of text. It's particularly useful for collecting longer form responses, comments, or any scenario requiring multi-line text input.
The component features a resizable input area, placeholder text support, and various customization options like auto-resize and validation capabilities.
Key features include:
- Resizable text area with drag handle
- Auto-resize capability based on content
- Placeholder text support
- Read-only mode
- Maximum length restriction
- Input validation
- Submit on Enter functionality
- Keyboard focus management
Examples
Basic TextArea with placeholder
Creates a simple TextArea with placeholder text and fixed dimensions.
<TextArea placeholder="Enter your message here..." style="height: 100px; width: 300px;" />
Auto-resizing TextArea with validation
Creates a TextArea that automatically resizes and validates input length.
var textArea = new TextArea {
autoResize = true,
autoShrink = true,
placeholder = "Enter at least 10 characters",
style = { minHeight = 50, width = 300 }
};
textArea.validateValue = (value) => value.Length >= 10;
textArea.RegisterValueChangedCallback(evt => {
Debug.Log($"Text is valid: {!textArea.invalid}");
});
Comment box with submission handling
Creates a comment box that submits on Shift+Enter with character limit.
<TextArea
placeholder="Write your comment..."
submit-on-enter="true"
submit-modifiers="Shift"
max-length="500"
style="min-height: 100px; width: 100%" />
Constructors
TextArea()
Default constructor.
Declaration
public TextArea()
TextArea(string)
Construct a TextArea with a predefined text value.
Declaration
public TextArea(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
inputUssClassName
The TextArea input styling class.
Declaration
public const string inputUssClassName = "appui-textarea__input"
Field Value
| Type | Description |
|---|---|
| string |
placeholderUssClassName
The TextArea placeholder styling class.
Declaration
public const string placeholderUssClassName = "appui-textarea__placeholder"
Field Value
| Type | Description |
|---|---|
| string |
resizeHandleUssClassName
The TextArea resize handle styling class.
Declaration
public const string resizeHandleUssClassName = "appui-textarea__resize-handle"
Field Value
| Type | Description |
|---|---|
| string |
scrollViewUssClassName
The TextArea input container styling class.
Declaration
public const string scrollViewUssClassName = "appui-textarea__scrollview"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The TextArea main styling class.
Declaration
public const string ussClassName = "appui-textarea"
Field Value
| Type | Description |
|---|---|
| string |
Properties
autoResize
Automatically resize the TextArea if the content is larger than the current size.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool autoResize { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
This will only grow the TextArea. It will not shrink it.
If the user manually resizes the TextArea, the auto resize will be disabled.
autoShrink
Whether the TextArea should automatically shrink if the content is smaller than the current size.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool autoShrink { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
To enable this feature, autoResize must be set to true.
contentContainer
The content container of the TextArea.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
invalid
The invalid state of the TextArea.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
isReadOnly
Whether the TextArea is read-only.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool isReadOnly { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
maxLength
The maximum length of the TextArea.
Declaration
[CreateProperty]
[UxmlAttribute]
public int maxLength { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
placeholder
The TextArea placeholder text.
Declaration
[CreateProperty]
[UxmlAttribute]
public string placeholder { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
submitActionKeyModifier
Whether the submit action should be triggered by using the Action key (Ctrl on Windows, Cmd on Mac) modifier.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool submitActionKeyModifier { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
submitModifiers
The modifiers required to submit the TextArea.
Declaration
[CreateProperty]
[UxmlAttribute]
public EventModifiers submitModifiers { get; set; }
Property Value
| Type | Description |
|---|---|
| EventModifiers |
submitOnEnter
Whether the TextArea should invoke the submitted event when the user presses the Enter key.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool submitOnEnter { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
validateValue
The validation function for the TextArea.
Declaration
[CreateProperty]
public Func<string, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<string, bool> |
value
The TextArea value.
Declaration
[CreateProperty]
[UxmlAttribute]
public string value { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
SetValueWithoutNotify(string)
Set the TextArea value without notifying the change.
Declaration
public void SetValueWithoutNotify(string newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | newValue | The new value of the TextArea. |
Events
submitted
Event triggered when the user presses the Enter key and submitOnEnter is true.
Declaration
public event Action submitted
Event Type
| Type | Description |
|---|---|
| Action |