a text field is an input field that users can type into. It has a range of options and supports several text formats including numbers.
Use to allow users to upload files.
<script lang="ts" setup>
import { FileField } from '@returnless/focus-ui';
</script>
<template>
<FileField label="Upload your file" name="file" v-model="fileInput" type="file" accept="image" />
</template>Use to allow users to upload multiple files. The multiple prop should be set to true.
<script lang="ts" setup>
import { FileField } from '@returnless/focus-ui';
</script>
<template>
<FileField label="Upload your file" name="file" multiple v-model="multipleFileInput" type="file" accept="image" />
</template>Text fields should:
The autocomplete attribute in an input field controls two types of browser behaviour:
autocomplete attribute. Review the section "4.10. 18.7 Autofill for all the input types and their corresponding autocomplete attribute values.Always add an autocomplete attribute and value to inputs if the type is: color, date, datetime-local, email, month, number, password, range, search, tel, text, time, url, or week.
Even if you do not want the browser to autofill a user's information, it is recommended you still have an autocomplete attribute with the value "off" or "nope".
Unfortunately, not all browsers support or respect autocomplete="off". This makes things challenging. Chrome, for example, has a long outstanding bug and won't add support for "off" for now.
Chrome does seem to turn autocomplete off when using the value nope (or any non-valid string). However, we have seen some inconsistencies even with that support.
Text fields can be grouped in a form or placed individually in the UI. Placeholder text should generally be avoided in text fields. Help text can be used below the text input area to guide the user on acceptable inputs.
Field labels act as a title for the text field. Labels should typically be short and in noun form. For example, "Name".
In general, avoid using placeholder text in text fields. It can pose a range of accessibility problems, like:
Exception: read the guidelines on [search fields].
Help text provides extra guidance or instructions to people filling out a form field. It and also be used to clarify how the information will be used.
Use help text:
Best practices for help text:
There are three types of text inputs:
Modeled text inputs are text field inputs that require text to be formatted in a specific way. For instance, tags need to be separated by commas, and dates need to be typed in YYYY-MM-DD format. Because modeled text inputs require a particular structure, always include examples that demonstrate how the user should enter the information.
Free text inputs accept a single string of text, without any particular structure. Use the field label to clearly indicate what should go in the text field.
Don't provide an example for free text inputs. The text doesn't follow a specific format, and we shouldn't assume what belongs in the field. If more context is needed, use help text.
If a text field label has a call to action, there's no need to repeat it in the help text. Instead, add a sentence that provides extra context.
For example, when a free text input is located independent of a form and has no surrounding context, you can make the field label a call to action.
If the text field label isn't clear about where the user can find the information, use help text to guide them.
Don't use placeholder text for free input titles, names, and descriptions; use help text instead.
Don't use placeholder text for codes or tracking numbers; use help text instead. If the code follows a standardized format, include an example, using the same format as help text for modeled content. If not, omit the example since the field's content can vary.
Choose clear names for the field label, and don't repeat it in the help text if possible. Instead, offer context that will help the user understand and complete the task quickly.
Multiline fields let users type long blocks of text. There are a few different versions:
Multiline inputs hold things like product and collection descriptions, notes about an order, and anything else the user wants to type into them.
We usually don't know what will go in multiline fields, so providing example text isn't helpful. Instead, include help text that explains how the text will be used and who can view it.
Screen readers convey information about text fields automatically through native HTML.
disabled prop to add the HTML disabled attribute to the text field.readOnly prop to add the HTML readonly attribute to the text field.type prop, then some assistive technologies will adept the software keyboard to the current task. This helps users with mobility, vision, and cognitive issues to enter information more easily.Use the id prop to provide a unique id attribute value for the text field. If you don't provide an id, then the component generates one automatically. All text fields need to have unique id values.
The label prop is required to convey the purpose of the checkbox to all users.
If there are separate visual cues that convey the purpose of the text field to sighted users, then the label can be visually hidden with the labelHidden prop.
When you provide help text via the helpText prop or an inline error message via the error prop, the help or error content is conveyed to screen reader users with the aria-describedby attribute. This attribute causes the content to be read along with the label, either immediately or after a short delay.
Use the placeholder prop to provide additional instructions. However, don't rely on placeholders alon since the content isn't always conveyed.
Text fields have standard keyboard support.
type is set to number, then users can use the up and down arrow keys to adjust the value typed into the field when hovering over or focusing the field to make the arrows appear.disabled prop will prevent the text field from receiving focus, and users won't be able to interact with it using the keyboard.readOnly prop allows focus on the text field but prevents input or editing.Although you can use the autoFocus prop to automatically move focus to the text field, it's generally best to avoid focusing on fields automatically. The autoFocus prop is set to false by default and should only be used in cases where it won't force focus to skip other controls or content of equal or greater importance.