The page navigation is complete. You may now navigate the page content as you wish.
Skip to main content

Text Input

A form element that provides users with a way to read, input, or edit data.

A Text Input is a form element that provides users with a way to read, input, or edit data.

Usage

When to use

  • As a form element that provides users with a way to read, input, or edit data in a freeform way.

When not to use

Types of text inputs

Text Input accepts a subset of types and offer built in styling for the following:

Text

Password

A password field has a visibility toggle. By default, a button appears allowing users to switch easily between visible and obfuscated input.

Text Input accepts the type of search which users can enter search queries into.

States

Default state
Loading state

While a query is running, a spinner takes the place of the search icon at the end of the field. Keep the field editable while it spins, so a user can correct the query without waiting.

Search placement

Do

Use a standalone search input when users are querying a broad dataset without the need for additional filtering controls, e.g., in the App Header or simple tables.

An example of the term "error" searched for across a simple dataset in a table

Don’t

Don't use a search input within a Filter Bar if no additional filters are present.

An example of the term "errored" searched for across a dataset in a table without additional filters

Date and time

Code consideration

Date and time fields use the native browser functionality for the popovers. Some browsers do not display an icon or popover.

Telephone

Required and optional

For complex forms, indicate required fields. This is the most explicit and transparent method and ensures users don’t have to make assumptions. Read more about best practices for marking required fields in forms.

Required

Optional

For shorter, simpler forms (e.g., login/signup and feedback requests), indicate optional fields instead.

Readonly, disabled, and hidden fields

Readonly, disabled, and hidden fields are very similar, but there are key differences to be aware of when choosing the correct type of Text Input. Since these fields are not editable by a user, we recommend using them sparingly.

Readonly

Readonly fields are not editable by the user but the value in the field is passed when the form is submitted.

Disabled

Disabled fields are also not editable by the user and the value in the field is not passed when the form is submitted.

Accessibility alert

Screen readers do not have access to disabled fields; therefore, we recommend against disabling fields. Please read more about showing, hiding, or disabling elements.

Hidden

Hidden fields are not visible to the user but the value in the field is passed when the form is submitted.

Field type Visible in UI Editable by user Value passed on submit
Readonly ✅ 🚫 ✅
Disabled ✅ 🚫 🚫
Hidden 🚫 🚫 ✅

Character Count

Consumer responsibility

The character count is not coupled with the invalid state of the field. Instead, it is the responsibility of the consumer to implement validation at the application-level.

Use a character count to communicate the current length of the value in an input and whether it meets or exceeds the length requirements of the field.

Default messages

Which requirements the field has decides the message: it names the relationship between the current length of the value and the maximum length, the minimum length, or both.

The default messages provide a consistent pattern: they state the length requirement and show how close the user is to meeting it.

A workspace name input with the text "work" entered. If the character count is showing current length, it reads "4 characters entered". If maximum length, it reads "21 characters remaining". If minimum length, it reads "1 character remaining".

Custom messages

A custom message in the character count is supported and can be used when a product or application-specific message or term is required, e.g., "registry" or "workspace".

Don’t

Avoid presenting duplicate information between the helper text and the character count. Helper text should be used to provide persistent requirements while character count represents more of a progress indicator towards a length requirement.

Workspace name input where the helper text says there is a 5 character minimum and the character count below the input also says there is a 5 character minimum.

Don’t

Don’t use the character count to display static details about the field. Use helper text to provide extra details about the information being requested and the character count to communicate the user’s progress toward meeting the requirements.

Error validation

For error validation recommendations, refer to the Form patterns documentation.

How to use this component

There are two ways to use <i80-text-input>:

  • the field: give the element a label attribute and it renders the <input> control, with label, helper text, and error messaging (in a wrapping container).
  • the base control: leave the label out and write your own <input> inside the element, which is kept as it is.

We recommend using the field as it provides built-in accessibility functionality. Use the base control if needing to achieve custom layouts or for special use cases not covered by the field.

The field

The basic invocation requires a label: the label attribute. This creates:

  • a <label> element with a for attribute automatically associated with the input ID attribute.
  • a <input type="text"> control with an automatically generated ID attribute.
<i80-text-input label="Cluster name" name="demo-cluster-name"></i80-text-input>

Input value

Pass a value to pre-populate the input.

<i80-text-input label="Cluster name" name="demo-cluster-name" value="my-cluster-1234"></i80-text-input>

Type

Pass a type to change the type of input.

Accessibility tips

type="number" is not supported as it causes accessibility and usability problems. If you are looking for additional validation or to display a numeric keypad on devices with dynamic keypads we recommend using inputmode="numeric" pattern="[0-9]*". For the list of supported types, see Component API.

<i80-text-input label="Email" type="email" name="demo-email" value="janedoe@email.com"></i80-text-input>
<i80-text-input label="Date of birth" type="date" name="demo-birthday"></i80-text-input>

Helper text

You can add extra information to the field using the helper-text attribute. When helper text is added, the component automatically adds an aria-describedby attribute to the input control, associating it with the automatically generated ID of the helper text element.

<i80-text-input label="AWS Account ID" helper-text="Copy this ID to your AWS Resource Access Manager to initiate the resource share." name="demo-aws-account-id" value="036140285924"></i80-text-input>

Required vs. optional

Use the required and optional attributes to add a visual indication that the field is "required" or "optional".

<i80-text-input label="AWS Account ID" helper-text="Copy this ID to your AWS Resource Access Manager to initiate the resource share." name="demo-aws-account-id" required></i80-text-input>
<i80-text-input label="AWS Account ID" helper-text="Copy this ID to your AWS Resource Access Manager to initiate the resource share." name="demo-aws-account-id" optional></i80-text-input>

Validation

To indicate a field is invalid, set the error attribute to the message: it shows the error and marks the control invalid.

<i80-text-input label="Email" type="email" name="demo-email" value="jane.doe@.com" error="The provided email is not valid."></i80-text-input>

Custom control ID

If needing a custom ID for the control instead of the one automatically generated by the component, write the <input> yourself inside the element with that id.

In this case all the internal references (id/for/aria-describedby) between the different parts of the field are still automatically generated and will use the custom ID provided.

<i80-text-input label="AWS Account ID" helper-text="Copy this ID to your AWS Resource Access Manager to initiate the resource share.">
  <input type="text" name="demo-aws-account-id" id="my-control">
</i80-text-input>

HTML native attributes

The element passes name, value, placeholder, autocomplete, minlength, maxlength, pattern, min, max, step, inputmode, list and form on to the <input> it creates. For any other native behavior, write the <input> yourself inside the element and it is kept as it is, with all its attributes.

<i80-text-input label="Password">
  <input type="password" name="demo-user-password" placeholder="Insert your password here" minlength="4" maxlength="64">
</i80-text-input>

Custom width

By default, the input control width is set to fill the parent container, with the exception of "date" and "time" input types.

Pass a custom width for the control using the width attribute.

<i80-text-input label="Filter the list:" type="search" name="demo-filter" placeholder="Search clusters" width="200px"></i80-text-input>

Password

By default, password fields render with a button allowing users to toggle between visible and obfuscated input content.

<i80-text-input label="Password" type="password" name="demo-password" value="1234567890"></i80-text-input>

You can remove the visibility toggle button by adding the no-visibility-toggle attribute.

<i80-text-input label="Password" type="password" name="demo-password" value="1234567890" no-visibility-toggle></i80-text-input>

The base control

The base control is intended for rare cases where the field can’t be used and a custom implementation is needed. Most of the details for the field also apply to it, but see the Component API for more details.

An <i80-text-input> without a label does not come with built-in accessibility functionality. It is the responsibility of the product team to ensure the implementation is conformant.

Write the <input> inside the element with its own type and an aria-label.

<i80-text-input>
  <input type="email" name="demo-email" value="janedoe@email.com" placeholder="eg. name.surname@email.com" aria-label="User email" required>
</i80-text-input>

Attributes

<i80-text-input> renders this component. Everything it understands:

Attribute Values Default Notes
label text Linked to the input.
helper-text text Linked with aria-describedby.
error text Shows the error and marks the input invalid.
required / optional boolean Adds the Required badge or (Optional).
type text · email · password · search · tel · url · number · date … text
name, value, placeholder, autocomplete, minlength, maxlength, pattern, min, max, step, inputmode, list, form Passed to the created <input>.
width CSS length
no-visibility-toggle boolean Password without the show/hide button.
aria-describedby id list Merged with the helper text and error ids the element links.

The tag keeps any native element you write inside it, so a server-rendered form, link or button works as it is. See Web Components for loading i80.js and the reference for these examples running.

Anatomy

Anatomy of the TextInput

Element Usage
Label Required
Indicator Optional
Helper text Optional
Placeholder/Value Optional
Control Required
Error message Triggered by system

States

Interactive states of the TextInput

For general content recommendations, refer to our Primitives documentation.

Conformance rating

A labelled field

Conformant

An <i80-text-input> with a label is conformant when used as directed, and is what we recommend by default. The label is a real <label for> pointing at the <input>, and the helper-text and error attributes are linked to it with aria-describedby, so a screen reader reads the name, the hint and the error together.

A field without a label

Conditionally conformant

A field is not conformant until it has an accessible name. If you leave the label attribute off — because the name is already in a table header or a heading nearby — put an aria-label on the element instead, or write your own <label for="…"> and <input> inside the tag; the element keeps the <input> you wrote and links the two.

Known issues

The helper text and the error are announced through aria-describedby, and a screen reader reads only their text. A link inside them is not announced as a link, so a keyboard user has no way to reach it from the announcement. Put links in the surrounding page content rather than in a label, helper text or error message.

Applicable WCAG Success Criteria

This section is for reference only, some descriptions have been truncated for brevity. This component intends to conform to the following WCAG Success Criteria:

  • 1.3.1 Info and Relationships (Level A):
    Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text.
  • 1.3.2 Meaningful Sequence (Level A):
    When the sequence in which content is presented affects its meaning, a correct reading sequence can be programmatically determined.
  • 1.3.4 Orientation (Level AA):
    Content does not restrict its view and operation to a single display orientation, such as portrait or landscape.
  • 1.3.5 Identify Input Purpose (Level AA):
    The purpose of each input field collecting information about the user can be programmatically determined when the input field serves a purpose identified in the Input Purposes for User Interface Components section; and the content is implemented using technologies with support for identifying the expected meaning for form input data.
  • 1.4.1 Use of Color (Level A):
    Color is not used as the only visual means of conveying information, indicating an action, prompting a response, or distinguishing a visual element.
  • 1.4.10 Reflow (Level AA):
    Content can be presented without loss of information or functionality, and without requiring scrolling in two dimensions.
  • 1.4.11 Non-text Contrast (Level AA):
    The visual presentation of the following have a contrast ratio of at least 3:1 against adjacent color(s): user interface components; graphical objects.
  • 1.4.12 Text Spacing (Level AA):
    No loss of content or functionality occurs by setting all of the following and by changing no other style property: line height set to 1.5; spacing following paragraphs set to at least 2x the font size; letter-spacing set at least 0.12x of the font size, word spacing set to at least 0.16 times the font size.
  • 1.4.3 Minimum Contrast (Level AA):
    The visual presentation of text and images of text has a contrast ratio of at least 4.5:1
  • 1.4.4 Resize Text (Level AA):
    Except for captions and images of text, text can be resized without assistive technology up to 200 percent without loss of content or functionality.
  • 2.4.6 Headings and Labels (Level AA):
    Headings and labels describe topic or purpose.
  • 2.4.7 Focus Visible (Level AA):
    Any keyboard operable user interface has a mode of operation where the keyboard focus indicator is visible.
  • 3.2.1 On Focus (Level A):
    When any user interface component receives focus, it does not initiate a change of context.
  • 3.2.2 On Input (Level A):
    Changing the setting of any user interface component does not automatically cause a change of context unless the user has been advised of the behavior before using the component.
  • 3.2.4 Consistent Identification (Level AA):
    Components that have the same functionality within a set of Web pages are identified consistently.
  • 3.3.1 Error Identification (Level A):
    If an input error is automatically detected, the item that is in error is identified and the error is described to the user in text.
  • 3.3.2 Labels or Instructions (Level A):
    Labels or instructions are provided when content requires user input.
  • 4.1.2 Name, Role, Value (Level A):
    For all user interface components, the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies.

Support

If any accessibility issues have been found within this component, let us know by submitting an issue.

0.1.0

Første i80-version (fork af upstream, se core/UPSTREAM.md).


Related