Text label: Inform users of what data should be put into the field, labels must always be outside of the text field.
Hint text: Serve as a guide to the user, helping to inform users as to what kind of data they are required to enter.
Icon (situational): Helps to make the input more specific or convey the functionality of the text input. E.g Search, dropdown, type of currency.
Error message: Serves to convey information on the error and allows the user to make the necessary correction.
Spacing
Within the text input
Ensure that there is a min of 8px vertical spacing and 16px horizontal spacing on the left and right.
Usage guidelines
Best practices:
Ensure that the labels are short and concise, so it’s obvious to the user what they should enter into the field.
Make sure your text inputs are far enough apart, so your user doesn’t click on the wrong one by mistake.
Make use of hint text to guide the user as to the format required. This removes uncertainty and will help reduce mistakes when filling in the text input.
Text input should be used when:
You need users to enter text that is only a single line.
You need freeform answers.
You need input simplicity. E.g Entering a date is easier than selecting from a date picker or calender.
Text input should not be used when:
You require users to enter text and/or long answers that span multiple lines.
Using the text area component would be more appropriate.
When you require users to select from a predetermined list.
Using the <select>, checkbox or radio button components would be more appropriate.
Usability guidelines
Labels should be placed outside of the text field
Labels should be above or next to the text field. This ensures a clear association between the label and the input field, and is also crucial for screen readers and other assistive technologies.
Do not rely solely on placeholder text to convey critical information
Placeholder text disappears when a text input is filled in, which can make it easy for users to forget the guidance or format instructions, leading to errors or confusion.
Text fields of the appropriate length
The length of the text input should correspond to the length of the expected answer. This will give the user an idea of how much they need to fill in.
Behaviour
Users should be able to click anywhere within the text area to focus. On focus, users can type directly into the text area. Any placeholder text in the field will be replaced when the user begins typing.
Accessibility guidelines
Aria attributes
Use the label element to associate text with form elements explicitly. The for attribute of the label must exactly match the id of the form control.
Keyboard accessibility
Ensure that the accordion can be navigated and operated using the keyboard:
Tab to bring focus to the text input.
Focus indicator
Ensure the focus indicator is highly visible. Use a distinct colour that contrasts well with the surrounding elements. Avoid relying on colour alone; consider adding a border or shadow to enhance visibility so that it is accessible to all users, including those with visual impairments.
The focus indicator should encompass the entire text input without altering its size or shape. It should be clear that the focus is on the text input, not another part of the UI.