A text field enables the user to enter a short amount of text into an interface or form.
The text field component enables a user to enter text into an interface. They are commonly used in:
The text field should be used when the user needs to enter a single line of text (for example, their name or email address.) If your use case requires the user to enter multiple lines of text (for example, a comment), use a text area instead.
Text fields are generally used with buttons to submit data into a system.
A text field component has:
An error message can also be displayed below the description when needed.
The text field supports the following states:
Design system components are published in a Figma library. Install the library and add it to your project to start using this component.
Text fields are highly modular. All of its parts (except the input field itself) can be shown or hidden as needed, depending on your use case.
If your use case requires hiding the input label, you must also provide a non-visible label using the aria-label property.
Control | Options | Description |
---|---|---|
Size |
|
Toggles between the default (medium) input size and a more compact version with reduced height |
State |
|
Toggles between different interaction states |
Show label |
|
Toggles on/off the label above the input |
Notification |
|
Toggles on/off the description below the input |
Show left icon |
|
Toggles on/off an icon to the left of the input |
Show right icon |
|
Toggles on/off an icon to the right of the input |
Detailed technical documentation, interactive previews and code samples are published in the B.C. Design System Storybook.
A reference implementation of the text field component in React is published in the React components library. Install the package via npm to start using the component.
The button component is a styled version of the React Aria text field component. Refer to the React Aria documentation for detailed information about:
The text field component has built-in support for HTML constraint validation (for example, by setting a type attribute or a minimum/maximum input length) and custom validation.
You can pass custom error messages programmatically to the error message slot below the input field.
These summaries reflect the component used as provided. If you modify it, confirm that your changes comply with the Web Content Accessibility Guidelines (WCAG). B.C. government digital services are required to meet the WCAG Level AA standard.
Requirement | WCAG Success Criterion | Validation |
---|---|---|
Make sure visual formatting is represented in the backend code | 1.3.1 (Level A) |
Label and input field are automatically associated via an aria-labelledby attribute |
Clearly define the purpose of input fields | 1.3.5 (Level AA) |
The input has a visible label, used to explain its purpose. The input type attribute can be set to provide an additional hint. Note: if you do hide the visible label, you must use aria-label to provide a semantic label |
Make websites keyboard accessible | 2.1.1 (Level A) |
Text field is focusable and fully operable using only the keyboard, with visual indicators for focused elements |
Prevent keyboard navigation traps | 2.1.2 (Level A) |
When in focus, the user can exit the text field by pressing the 'Tab' key |
Show where the keyboard is active on the screen | 2.4.7 (Level AA) |
Focus is indicated with a visible and offset secondary border around the input field |
Make sure interaction or click targets meet a minimum size | 2.5.8 (Level AA) |
The input field has a minimum target area of 32px by 32px |
Ensure user interface components behave predictably | 3.2.1 (Level A) |
Input value does not change and is not submitted on focus |
Make sure components can be read and used by assistive technology | 4.1.2 (Level A) |
The input field is automatically associated to its label via an aria-labelledby attribute, and has the input role |