TextField
is used for user input. You would use it in forms when user input is required or for search. A TextField may be a single line or have multiple lines (textarea). Look into Forms for more on how to add labels and group inputs together.
For information on TextField/TextArea and Form style and usage guidelines, check out TextField Design Guidelines and Form Design Guidelines.
Example
A default TextField.
Text Areas
In order to have a multi-line text field, you must set it as a textarea
. You can then define how many lines you would like the TextField
to be.
Error State
You may provide styling for error state via the error
prop - the border color will change and the respective icon will show on the right side. The TextField will not do any automatic text validation - you must manually trigger the error style. Look into Form
on form validation. You may choose between default
, error
, warning
, and success
.
Other Styling
You may disable a TextField
via the disabled
prop. You could also add an svg icon without changing the error state via the icon
prop.
Common Props
TextField
includes COMMON
and COLOR
common props. Read Common Props for details and API. These common props will override component props such as the color.
Prop name | Type | Default | Description |
---|---|---|---|
aria-label | String | this should be set when the input's label is not visible on the screen | |
as | textarea | determines if the input is multiline or not | |
autoComplete | String | HTML autocomplete attribute | |
disabled | Boolean | false | disable input |
error | default | error | warning | success | 'default' | set the error state |
icon | ReactNode | null | set the icon component, displayed on the left of the input |
id | String | input ID - this should be the same as a label's for prop | |
lines | Number | 3 | Number of lines a textarea should be - this should only be used when as=textarea |
name | String | HTML name attribute | |
onChange | Func | callback to execute on user input | |
placeholder | String | the text to display in the input before typing | |
theme | Object | Bridge Theme | use to override default bridge theme |
type | email | number | password | tel | text | url | date | 'text' | the type of content (for textarea , use as=textarea ) |
value | String | the value of the content input |