docs/documentation/components/text-input.mdx
Evergreen exports two components to create text inputs:
input element.The TextInput component is a basic text input component.
It directly maps to a input element.
<TextInput name="text-input-name" placeholder="Text input placeholder..." />
The TextInput component works the same as using input directly.
Use e.target.value to get the value of the component on change.
function ControlledTextInputExample() {
const [value, setValue] = React.useState('')
return <TextInput onChange={e => setValue(e.target.value)} value={value} />
}
<TextInput disabled />
<TextInput isInvalid />
The TextInputField component combines a TextInput with a label and optional
description, validationMessage and hint.
<TextInputField
label="Default text input field"
description="This is a description."
placeholder="Placeholder text"
/>
<TextInputField
label="Default text input field"
hint="This is a hint."
placeholder="Placeholder text"
/>
<TextInputField
id="ids-are-optional"
label="A required text input field"
required
description="This is a description."
placeholder="Placeholder text"
/>
<TextInputField
isInvalid
required
label="A required text input field"
description="This is a description."
validationMessage="This field is required"
/>
<TextInputField
isInvalid={false}
required
label="A required text input field"
description="This is a description."
validationMessage="This field is required"
/>
The TextInputField component works the same as using input directly.
Use e.target.value to get the value of the component on change.
function ControlledTextInputExample() {
const [value, setValue] = React.useState('')
return (
<TextInputField
label="A controlled text input field"
required
description="This is a description."
value={value}
onChange={e => setValue(e.target.value)}
/>
)
}