Skip to content

Input

Input components are essential UI elements that allow users to enter and edit text. They come in two main variants: single-line text inputs and multi-line text areas. Each type supports various states including basic, error, custom error messages, and disabled states.

Single-line Text Inputs

Basic Input

The basic text input includes a label, placeholder text, and optional helper text. The width will default to 100%, but can restrained using additional CSS as is done in these examples.

Helper text

Error State

The error state indicates invalid input with red borders and an error message. It can be applied by changing the aria-invalid attribute to true.

Helper text

Disabled State

The disabled attribute can be applied to the <input/> element to style the whole component to its disabled state.

Helper text

Clearable Input

Inputs can include a clear button to quickly remove entered text, although the functionality for this must be added in javascript. The clear button appears when the text input contains text.

Helper text

Text Areas

Basic Text Area

Text areas provide multi-line input capabilities with optional character limits. They behave in the same way as the <input/> above, but use a <textarea/> element instead.

Error State

Text areas support the same error states as single-line inputs. ike in the single line input, this is activated by changing the aria-invalid attribute to true.

Disabled State

Text areas also support the disabled state. Like in the single line input, this is activated by applying the disabled attribute to the <textarea/>.

CSS Variables

The input system can be customized using the below CSS variables:

VariableDefault ValueDescription
--input-spacing0.25remGap between input elements
--input-padding-x0.5remHorizontal padding
--input-padding-y0.75remVertical padding
--input-border-width1pxDefault border width
--input-border-width-active2pxBorder width when active
--input-border-width-invalid2pxBorder width in error state
--input-error-border-colorvar(--color-error)Border color in error state
--input-radiusvar(--radius-site)Border radius for inputs
--input-radius-textareavar(--radius-site)Border radius for textareas

Accessibility

The input system is built following WCAG guidelines and WAI-ARIA best practices for form inputs, implementing key accessibility features through semantic HTML and ARIA attributes.

Current Implementation Features

Structure and Labeling

Each input includes:

  • Semantic HTML with proper <label> elements explicitly linked to inputs via for attributes
  • aria-invalid attribute to communicate validation state
  • aria-describedby to associate helper text with inputs
  • aria-errormessage to link error messages with inputs
  • Visible labels that remain visible in all states
  • Helper text for additional context
  • Error messages that are announced by screen readers via role="alert"

Visual States

The system provides clear visual indicators for:

  • Default state with distinct borders
  • Focus state with visible outlines
  • Error state with high-contrast borders and background
  • Disabled state with muted colors and disabled cursor
  • Hover state with enhanced borders

Screen Reader Support

Each input variant includes:

  • Clear labeling of all interactive elements
  • Helper text linked via aria-describedby
  • Error messages linked via aria-errormessage
  • Character count updates for text areas using aria-live="polite"
  • Clear button with descriptive aria-label
  • Error icons hidden from screen readers with aria-hidden="true"

Required JavaScript Implementation

While the components are built to be functional without JavaScript, some features require JavaScript for full accessibility:

Character Counter

For text areas with character limits:

  • Update the character count text as the user types
  • Announce updates to screen readers via the aria-live region

Clear Button

For inputs with clear functionality:

  • Reset focus to the input field after clearing
  • Announce the clear action to screen readers

Error Handling

For proper error management:

  • Set aria-invalid="true" when validation fails
  • Update error messages dynamically
  • Focus the first invalid field when form submission fails
  • Announce error messages to screen readers

Keyboard Navigation

The native HTML elements provide:

  • Tab key to navigate between inputs
  • Space/Enter to activate the clear button
  • Arrow keys for cursor movement within inputs
  • Standard text editing shortcuts (when implemented by the browser)

Mobile Accessibility

For mobile devices:

  • Touch targets meet minimum size requirements
  • Clear visual feedback for all states
  • Native input behaviors maintained
  • Proper viewport zooming supported
  • Clear button positioned for easy touch access

Required Implementation Steps

When implementing inputs in your project, ensure you:

HTML Structure

  • Maintain the semantic structure of labels, inputs, and helper text
  • Keep error messages in the correct order for screen reader announcement
  • Preserve all ARIA attributes and relationships

Error Handling

  • Implement client-side validation where appropriate
  • Ensure error messages are clear and actionable
  • Maintain proper focus management during validation

JavaScript Enhancements

  • Add character counter functionality for text areas
  • Implement clear button functionality
  • Handle dynamic error states and announcements