Text field

A text field is an input field that merchants can type into. It has a range of options and supports several text formats including numbers.

Examples

Use to allow merchants to provide text input when the expected input is short. For longer input, use the auto grow or multiline options.

Drag to resize example

Props

align
"left" | "center" | "right"
Determines the alignment of the text in the input
ariaActiveDescendant
string
Indicates the id of a related component’s visually focused element to the input
ariaAutocomplete
string
Indicates what kind of user input completion suggestions are provided
ariaControls
string
Indicates the id of a component controlled by the input
ariaOwns
string
Indicates the id of a component owned by the input
autoComplete
boolean | string
Enable automatic completion by the browser
autoFocus
boolean
Automatically focus the input
clearButton
boolean
Show a clear text button in the input
connectedLeft
React.ReactNode
An element connected to the left of the input
connectedRight
React.ReactNode
An element connected to the right of the input
disabled
boolean
Disable the input
error
string | ReactElement | (string | ReactElement)[] | boolean
Error to display beneath the label
focused
boolean
Force the focus state on the input
helpText
React.ReactNode
Additional hint text to display
id
string
ID for the input
labelRequired
string
Label for the input
labelAction
Action
Adds an action to the label
labelHidden
boolean
Visually hide the label
max
number
Mimics the behavior of the native HTML attribute, limiting how high the spinner can increment the value
maxLength
number
Maximum character length for an input
min
number
Mimics the behavior of the native HTML attribute, limiting how low the spinner can decrement the value
minLength
number
Minimum character length for an input
multiline
boolean | number
Allow for multiple lines of input
name
string
Name of the input
pattern
string
A regular expression to check the value against
placeholder
string
Hint text to display
prefix
React.ReactNode
Text to display before value
readOnly
boolean
Disable editing of the input
role
string
Defines a specific role attribute for the input
showCharacterCount
boolean
Indicates whether or not the character count should be displayed
spellCheck
boolean
Indicate whether value should have spelling checked
step
number
Limit increment value for numeric and date-time inputs
suffix
React.ReactNode
Text to display after value
type
"text" | "email" | "number" | "password" | "search" | "tel" | "url" | "date" | "datetime-local" | "month" | "time" | "week" | "currency"
Determine type of input
value
string
Initial value for the input
onBlur
() => void
Callback when focus is removed
onChange
(value: string, id: string) => void
Callback when value is changed
onClearButtonClick
(id: string) => void
Callback when clear button is clicked
onFocus
() => void
Callback when input is focused

Accessibility

Structure

Screen readers convey information about text fields automatically through native HTML.

  • Use the disabled prop to add the HTML disabled attribute to the text field.
  • Use the readOnly prop to add the HTML readonly attribute to the text field.
  • If you use the type prop, then some assistive technologies adapt the software keyboard to the current task. This helps merchants 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.

Labeling

The label prop is required to convey the purpose of the checkbox to all merchants.

If there are separate visual cues that convey the purpose of the text field to sighted merchants, 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 alone since the content isn’t always conveyed to all merchants.

Do

  • Use the label to provide instructions critical to using the text field
  • Use help text and placeholder text to provide additional, non-critical instructions

Don’t

Use the placeholder to provide information that’s required to use the text field.

Keyboard support

Text fields have standard keyboard support.

  • Merchants who rely on the keyboard expect to move focus to each text field using the tab key (or shift + tab when tabbing backwards)
  • If the type is set to number, then merchants can use the up and down arrow keys to adjust the value typed into the field
  • Using the disabled prop will prevent the text field from receive keyboard focus or inputs
  • The readOnly prop allows focus on the text field but prevents input or editing

Automatically focusing

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.

Autocomplete

  • Use the ariaControls and ariaOwns props (which implement the aria-controls and aria-owns attributes) to point to the id of the autocomplete list.
  • Use the ariaAutocomplete prop to indicate what kind of aria-autocomplete input is provided, either list or inline. Typically, list is used.
  • When merchants navigate through the list, the ariaActiveDescendant prop indicates which option has programmatic focus so that it can be conveyed to screen reader users.

To learn more about implementing a text field with autocomplete, see the autocomplete component.

Default text field

Use to allow merchants to provide text input when the expected input is short. For longer input, use the auto grow or multiline options.

Default text field

Number field

Use when input text should be a number.

This will display the right keyboard on mobile devices.

Number text field with numeric keyboard

Email field

Use when the text input should be an email address.

This will display the right keyboard on mobile devices.

Email field with email keyboard

Multiline text field

Use when the expected input could be more than one line. The field will automatically grow to accommodate additional text.

Multi-line text field

TextField with right aligned text

Use when input text should be aligned right.

Text field with placeholder text

Use to provide a short, non-essential hint about the expected input. Placeholder text is low-contrast, so don’t rely on it for important information.

Default text field with placeholder text hint

Text field with help text

Use to show short instructional content below the text field. Use especially when incorrect formatting will result in an error and merchants don’t know what format is required (e.g. to explain the correct format for dates, or requirements for a password). If more explanation is needed, link to the Shopify Help Center.

Default text field with help text

Text field with prefix or suffix

Use as a special form of help text that works best inline.

  • Use a prefix for things like currency symbols (e.g. “$”, “¥”, “£”).
  • Use suffix for things like units of measure (e.g. “in”, “cm”).

Default text field with prefix and suffix

Text field with connected fields

Use when a text field and several related fields make up a logical unit.

If inputting weight as a number and a separate unit of measurement, use a text field with a selector (e.g. “kg”, “lb”) as a connected field.

Text field with connected selector

Text field with icon action

Use to let merchants take an action within the text field.

For example, tap on a barcode icon to launch the camera and scan barcode for the barcode field. This helps merchants simplify their input.

Text field with icon action inside the text field

Text field with validation error

Use to let merchants know if their input is valid or if there’s an error. Whenever possible, validate input as soon as merchants have finished interacting with a field (but not before). If a field already has an error, validate and remove errors as merchants type so they can immediately see when an error has been fixed.

Text field with error

Accessibility

See Material Design and development documentation about accessibility for Android:

Default text field

Use to allow merchants to provide text input when the expected input is short. For longer input, use the auto grow or multiline options.

Default text field

Number field

Use when input text should be a number.

This will display the right keyboard on mobile devices.

Number text field with numeric keyboard

Email field

Use when the text input should be an email address.

This will display the right keyboard on mobile devices.

Email field with email keyboard

Multiline text field

Use when the expected input could be more than one line. The field will automatically grow to accommodate additional text.

Multi-line text field

TextField with right aligned text

Use when input text should be aligned right.

Text field with placeholder text

Use to provide a short, non-essential hint about the expected input. Placeholder text is low-contrast, so don’t rely on it for important information.

Default text field with placeholder text hint

Text field with help text

Use to show short instructional content below the text field. Use especially when incorrect formatting will result in an error and merchants don’t know what format is required (e.g. to explain the correct format for dates, or requirements for a password). If more explanation is needed, link to the Shopify Help Center.

Default text field with help text

Text field with prefix or suffix

Use as a special form of help text that works best inline.

  • Use a prefix for things like currency symbols (e.g. “$”, “¥”, “£”).
  • Use suffix for things like units of measure (e.g. “in”, “cm”).

Default text field with prefix and suffix

Text field with connected fields

Use when a text field and several related fields make up a logical unit.

If inputting weight as a number and a separate unit of measurement, use a text field with a selector (e.g. “kg”, “lb”) as a connected field.

Text field with connected selector

Text field with icon action

Use to let merchants take an action within the text field.

For example, tap on a barcode icon to launch the camera and scan barcode for the barcode field. This helps merchants simplify their input.

Text field with icon action inside the text field

Text field with validation error

Use to let merchants know if their input is valid or if there’s an error. Whenever possible, validate input as soon as merchants have finished interacting with a field (but not before). If a field already has an error, validate and remove errors as merchants type so they can immediately see when an error has been fixed.

Text field with error

Accessibility

See Apple’s Human Interface Guidelines and API documentation about accessibility for iOS:

Best practices

Text fields should:

  • Be clearly labeled so it’s obvious to merchants what they should enter into the field
  • Be labeled as “Optional” when you need to request input that’s not required
  • Only ask for information that’s really needed
  • Validate input as soon as merchants have finished interacting with a field (but not before)

Content guidelines

Field label

A label is a short description of the requested input. Labels are not instructional text but they should be meaningful and clearly indicate what is expected. Labels should be:

  • Placed above or beside the form field
  • Short and succinct (1–3 words)
  • Written in sentence case (the first word capitalized, the rest lowercase)
  • Email address

  • Phone number

  • What is your email address?

  • My phone number is:

Field placeholder text

Placeholder text is shown inside the form field to teach merchants what to input. Field placeholder text should:

  • Be used only for supplementary information because the text has low contrast and is not visible when text is entered
  • Be written as examples instead of instructions
  • Include “e.g.” before an example
  • e.g. FALLSALE

  • Name your discount code

Designating optional fields

Try to only ask for information that’s required. If you need to ask merchants to provide optional information, mark the field optional by placing the text “(optional)” at the end of the field’s label. Don’t mark required fields with asterisks.

  • Phone number (optional)

  • First name*

Help text

Help text provides extra guidance or instruction to people filling out a form field. It can also be used to clarify how the information will be used. As with all form content, help text should be succinct and easy to read.

  • 9-digit number

  • Example: 123-456-789

Validation error messages

Error messages should:

  • Clearly explain what went wrong and how to fix it
  • Be short and concise, no more than a single sentence
  • Use passive voice so merchants don’t feel like they’re being blamed for the error
  • Store name is required

  • You didn’t enter a store name.