Text Field

Allows users to enter short pieces of text.

Description

A text field

Design Problem

Provide a user somewhere to enter a limited length piece of text. There should be some indication of how much text is expected (but not necessarily a hard limit).

Description

The text field allows users to enter short pieces of text.

The field should take focus when clicked, or when the tabbed into (see Forms).

It has a number of states it can be in

To make forms easier to fill in, it's useful to be able to give the user clues about what is expected. One important clue is how much are they expected to type.

Form fields should indicate this by their size - which should be large enough to contain the expected input, with a little spare for comfort.

Detailed description, including

When to use

Text Fields work well for short pieces of text, typically in a form. They typically don't need validation - if they do then they're probably a more specific type of text field, such as a date or email address.

Text Fields work well for short pieces of text, typically in a form. They typically don't need validation - if they do then they're probably...

Describe the context when this component is most appropriate. Something like

Widgets work best when...

Describe when it may be less appropriate, even though it might technically work. For example, (for radio buttons)

Don't use radio buttons if there are more than about 5 options. When there are too many options they take up too much UI space. It also becomes harder to see which option is currently selected when there are too many options.

Don't mentions the alternatives here (they belong in the Alternatives section below) this should all be about the component in question. Instead explain how this component fails in specific (or perhaps extreme) scenarios.

Variations

At the moment there are only two sizes available, "Default" and "Small".

List any variations, with illustrations where feasible. If there are multiple dimensions of variations (for example, different size and different colours) then it's not necessary to list every possible combination, but just give a representative sample.

It's important to describe when the various variations would be used.

Related

Any related components. These are not alternatives, but might be:

Accessibility

Any accessibility issues which this component raises. This should be design-focussed for this section, not technical. (Technical accessibility issues should be documented in the Implementation Guidance tab).

Implementation

Mention any implementations here, with links to the repository and specific code where possible. E.g.

Developer documentationCSS implementation

Document the various classes available here. For components which have a more complex HTML structure, describe the class structure across the entire component.

For example, for the progress bar component, the HTML structure is

<div class="ul-progress -medium">
        <div class="ul-progress__message">Submitting...</div>
        <div class="ul-progress__status">33% complete</div>
        <div class="ul-progress__bar">
          <div class="ul-progress__barComplete" style="width: 33%"></div>
        </div>
      </div>
      
CSS classes
HTML Element Class Meaning
div (outermost element) ul-progress This makes this component as being a progress bar
div (outermost element) -medium Sets the size to medium
div (outermost element) -small Sets the size to small
div (outermost element) -indeterminate Bar is indeterminate, so doesn't show progress, only "activity"
div div[0] ul-progress__message Contains the message which appears above the progress bar
div div[1] ul-progress__status Contains the progress percentage, or number of items completed, or time remaining.
div div[2] ul-progress__bar Is the track for the progress bar
div div[2] div ul-progress__barComplete Is the progress bar itself. Note the style attribute to set the actual value.

Template: This is an example only. The progress bar documentation my change in future!

Implementation GuidanceCSS Variables

Describe any CSS variables which should affect the component. For example, ones used to set colours, border radius and so on.

Semantics

Describe any semantic HTML which should be used when implementing this. This may be used inside a component, but should be respected for accessibility reasons. e.g. for the Progress Bar

This should be implemented using the HTML progress element, like so:

<progress id="file" max="100" value="70">70%</progress>
      
Accessibility

Any other accessibility guidance should be shown here, for example ARIA attributes.

Alternative CSS for screen readers should also be indicated here.

Testing

Describe any testing which should be done on the implementation.