Components
TextField
TextField is a control that displays an editable text interface. TextField is used to collect single-line text input from users.
TextField is a control that displays an editable text interface. TextField is used to collect single-line text input from users.
Examples
Basic Usage
Preview unavailable for this example in the static docs build.
Show code
<VStack spacing={16}>
<TextField placeholder="Enter text here" />
<TextField placeholder="Disabled field" disabled />
<TextField placeholder="Email" type="email" />
</VStack>With Value
Preview unavailable for this example in the static docs build.
Show code
const TextFieldWithValueDemo = () => {
const [value, setValue] = useState('Hello World')
return (
<VStack spacing={16}>
<Text>Current value: {value}</Text>
<TextField
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="Type something..."
/>
</VStack>
)
}API
| Prop | Type | Required | Description |
|---|---|---|---|
value | string | No | The current value of the text field. |
onChange | (event: React.ChangeEvent<HTMLInputElement>) => void | No | Callback fired when the value changes. |
placeholder | string | No | Placeholder text displayed when the field is empty. |
disabled | boolean | No | Whether the text field is disabled. Default: false |
type | 'text' | 'email' | 'tel' | 'url' | 'search' | 'password' | No | The type of input. Defaults to 'text'. Default: 'text' |
Inherits additional props from Omit<IBaseElementComponent<'input'>, 'type' | 'children'>.
Overview
TextField is a control that displays an editable text interface. TextField is used to collect single-line text input from users.
SwiftUI Correspondence: Similar to SwiftUI's TextField.
With Value
Control the text field value:
Notes
- TextField supports controlled and uncontrolled modes
- Use
valueandonChangefor controlled inputs - TextField supports common text-entry input types such as text, email, tel, url, search, and password
- Use
placeholderto provide hints about expected input - TextField can be disabled with the
disabledprop
Best Practices
- Labels: Always provide labels or placeholders for text fields
- Validation: Validate input on blur or submit
- Feedback: Provide clear feedback for invalid inputs
- Accessibility: Use proper labels and ARIA attributes
- Mobile: Ensure text fields are properly sized for mobile keyboards