TextField
A text field allows a user to enter a plain text value with a keyboard.
isReadOnly
isDisabled
Value
Use the value
or defaultValue
prop to set the text value, and onChange
to handle user input.
Your name:
import {TextField} from './TextField';
import {useState} from 'react';
function Example() {
let [name, setName] = useState('');
return (
<>
<TextField
label="Name"
value={name}
onChange={setName} />
<p>Your name: {name}</p>
</>
);
}
Forms
Use the name
prop to submit the text value to the server. Set the isRequired
, minLength
, maxLength
, pattern
, or type
props to validate the value, or implement custom client or server-side validation. See the Forms guide to learn more.
TextArea
Use <TextArea>
instead of <Input>
to enable multi-line input.
import {TextField, Label, TextArea} from 'react-aria-components';
<TextField>
<Label>Comment</Label>
<TextArea />
</TextField>