TextEditor
TextEditor is a native `<textarea>`-backed multiline editor for longer text such as comments, descriptions, and notes.
TextEditor is a native `<textarea>`-backed multiline editor for longer text such as comments, descriptions, and notes.
Examples
Basic Usage
Preview unavailable for this example in the static docs build.
Show code
<TextEditor defaultValue="Start with a draft here..." placeholder="Enter notes..."></TextEditor>Controlled Usage
Preview unavailable for this example in the static docs build.
Show code
function ControlledTextEditor() {
const [value, setValue] = useState('Draft message')
return (
<VStack spacing={10}>
<Text>Character count: {value.length}</Text>
<TextEditor
aria-label="Controlled message"
value={value}
onValueChange={setValue}
placeholder="Write a response..."
/>
</VStack>
)
}Content Sizing
Preview unavailable for this example in the static docs build.
Show code
<TextEditor defaultValue="Line 1\nLine 2\nLine 3\nLine 4" placeholder="Enter release notes..."></TextEditor>Read Only
Preview unavailable for this example in the static docs build.
Show code
<TextEditor defaultValue="You can copy this text, but not edit it." readOnly></TextEditor>Disabled State
Preview unavailable for this example in the static docs build.
Show code
<TextEditor defaultValue="This editor is disabled." disabled></TextEditor>API
| Prop | Type | Required | Description |
|---|---|---|---|
value | string | No | The current value of the editor. |
defaultValue | string | No | The initial value of the editor when uncontrolled. |
onChange | ChangeEventHandler<HTMLTextAreaElement> | No | Native textarea change handler. |
onValueChange | (value: string) => void | No | Value-first change handler for SwiftUI-style ergonomics. |
placeholder | string | No | Placeholder text |
rows | number | No | Native textarea row count. When omitted, TextEditor grows with content and keeps a sensible size between 3 and 8 rows based on its current content. |
Inherits additional props from Omit<IBaseElementComponent<'textarea'>, 'children' | 'value' | 'defaultValue' | 'onChange'>.
Overview
TextEditor is a native <textarea>-backed multiline editor for longer text such as comments, descriptions, and notes.
SwiftUI Correspondence: Similar to SwiftUI's TextEditor, with a web-native onChange event plus onValueChange for value-first updates.
Controlled Usage
Use value with onValueChange when the parent owns the text state:
Content Sizing
When rows is omitted, TextEditor derives a sensible row count from explicit line breaks in the current content and keeps it between 3 and 8 rows:
Read Only
TextEditor can be displayed as read only:
Notes
defaultValuecreates an uncontrolled editor that still behaves like a normal textareavaluekeeps the editor controlled by the parentonChangereceives the native textarea change eventonValueChangereceives the latest string value for SwiftUI-style state updatesplaceholder,disabled, andreadOnlybehave like native textarea propsrowscan be set explicitly, otherwise the editor derives a sensible row count from explicit line breaks in its content
Best Practices
- Controlled vs uncontrolled: Pick one mode and keep it consistent.
- Labels: Provide an accessible label or use an associated
<Label>. - Sizing: Use
rowswhen you need a fixed height; otherwise the editor sizes itself from explicit line breaks. - Validation: Validate input length and content at the form level.
- Accessibility: Keep the native textarea semantics intact for keyboard and assistive tech users.
Text
Text is a view that displays one or more lines of read-only text. Use Text to display a string in your app's user interface. The Text view draws a string in a given font, with support for multiple lines, text truncation, and wrapping.
TextField
TextField is a control that displays an editable text interface. TextField is used to collect single-line text input from users.