Text fields allow users to input custom text entries with a keyboard. Various options can be shown with the field to communicate the input requirements.
Examples
$refs.firstTab.focus())"
>
Options
Label
Text fields should always have a label. In rare cases where context is sufficient and the UX Team have reviewed the design, the label could be undefined. These text fields without a visible label should still include an aria-label in HTML (depending on the context, “aria-label” or “aria-labelledby”).
Label Position
Labels can be placed either on top or on the side. Top labels are the default and are recommended because they work better with long copy, localization, and responsive layouts. Side labels should be used sparingly; they are most useful when vertical space is limited. Additional
utility classes may be needed for label maximum widths and alignments etc.
Value
The value shows a user’s entered text.
Width
The width of a text field can be customized appropriately for its context.
Size
Text fields come in three different sizes: small, medium and large. The medium size is the default and most frequently used option. Use the other sizes sparingly; they should be used to create a hierarchy of importance within the page.
Optional
By default text fields are assumed required and have no indication at all (such as an asterisk, as hint text would then need to be included to explain what it means). Text fields can be marked as optional. Optional text fields are denoted with text added to the end of the label — “(optional)”.
Character Count
Text fields can display a character count indicator when the length of the text entry needs to be kept under a predefined value. Character count indicators can be used in conjunction with other indicators (e.g. “optional” indicators) when necessary.
Error
A text field can be marked as having an error to show that a value needs to be entered in order to move forward or that a value that was entered is invalid. If an error exists, the error icon always overrides any other icon.
Disabled
A text field in a disabled state shows that an input field exists, but is not available in that circumstance. This can be used to maintain layout continuity and communicate that a field may become available later.
Read Only
Text fields have a read-only option for when content in the disabled state still needs to be shown. This allows for content to be copied, but not interacted with or changed. A text field does not have a read-only option if there is nothing entered in it.
Help Text
A text field can have help text below the field to give extra context or instruction about what a user should input in the field. The help text area has two options: a description and an error message. The description communicates a hint or helpful information, such as specific requirements for correctly filling out the field. The error message communicates an error for when the field requirements aren’t met, prompting a user to adjust what they had originally input.
Input Type
A text field can have multiple input types, depending on the need and use case. Text fields have a text input type by default. There are many types supported (see Form Elements) but some example use cases are:
Text defines a single-line text field.
URL defines a field for entering a URL.
Phone defines a field for entering a telephone number.
Email defines a field for entering an email address.
Password defines a password field. As a user enters a value, the text changes to dots.
Behaviors
Minimum Width
The minimum width for a text field is 1.5× the height of the field. This minimum width guarantees that small text fields are readable and easy to target on touch devices.
Text Overflow
When the field label is too long for the available horizontal space, it wraps to form another line. The field text itself truncates.
Help Text Overflow
When the help text is too long for the available horizontal space, it wraps to form another line.
$refs.secondTab.focus())"
>
Implementation
Example Name
Description and implementation notes
<p> code example </p>
$refs.thirdTab.focus())"
>
Information
Checklist
All interactive states
Includes all interactive states that are applicable (hover, down, focus, keyboard disabled).
All Color Schemes
Works properly across all color schemes (light, dark).
Accessible Contrast for Text
Text has a contrast ratio of at least 4.5:1 for small text and at least 3:1 for large text (WCAG 2.0 1.4.3).
Accessible Contrast for UI Components
Visual information required to identify components and states (except inactive components) has a contrast ratio of at least 3:1 (WCAG 2.1 1.4.11).