Text Field
A form control that accepts a single line of text.
Examples
Helper text and placeholder
The placeholder
prop can be used to show the user how to format the data we are asking for.
It is not needed when the format is made obvious by the label
, for e.g "Email".
The helperText
prop can be used to provide additional information about the input field below it.
Invalid state
If the isInvalid
prop is set to true, the errorMessage
contents will be displayed below the
input field, replacing helperText
.
With suffix
Providing the suffix
prop will append a text to the right of the input field. Suffix is useful for
displaying units.
Enhance user experience
Consider providing additional properties to enhance the user experience, such as inputMode
. For
example, using inputMode="decimal"
shows a numeric keyboard on mobile devices which makes it
easier for users to enter numbers.
Accessibility
- Provide a clear
label
for the text field that describes its purpose. - Use the appropriate
type
prop to ensure the correct keyboard is displayed on mobile devices. - Use the
helperText
anderrorMessage
props to provide additional context to the user.
API Reference
Prop | Default | Description |
---|---|---|
label | - | string The label for the input |
type? | - | HTMLInputTypeAttribute |
suffix? | - | string Suffixed text to display after the input. This is useful for e.g. displaying units of measurement. |
value? | - | string | number | readonly string[] |
helperText? | - | string Text that provides additional guidance to the user |
isInvalid? | - | boolean If |
isDisabled? | - | boolean If |
isOptional? | - | boolean If |
isRequired? | - | boolean If |
errorMessage? | - | string The error message to display if |
inputMode? | - | "search" | "text" | "email" | "tel" | "url" | "none" | "numeric" | "decimal" Hints at the type of data that might be entered by the user while editing the element or its contents |
step? | - | string | number |