Command Palette

Search for a command to run...

Components · Core component

TextInput

The Text Input component is a complete form control including a label, input, and help text. Text Input also supports optional description and error message elements, which can be used to provide more context about the field, and any validation messages. These are linked with the input via the aria-describedby attribute.

Features

Text Input is automatically connected to handle Accessibility features. Text input has some features baked in to make it easier to use and more consistent.

  • Built with a native <input> element
  • Visual and ARIA labeling support
  • Change, clipboard, composition, selection, and input event support
  • Required and invalid states exposed to assistive technology via ARIA
  • Support for description and error message help text linked to the input via ARIA

Usage

TSX
import { TextInput } from '@console/nimbus-ui/core';

Examples

With Label

The label prop can be used to generate a label for the input. This props sets the htmlFor attribute to a random generated id. You are able to overwrite the this attribute if you need to take control of the htmlFor prop.

Addon

TextInput component provides the ability to include addons on both the left and right sides of the input field. Each prop accepts a React.Node, allowing for the flexibility to set them statically or dynamically based on the component's properties.

Loading

TextInput allows a togglable state for loading using the loading prop. This prop will create a spinner inside of the TextInput component to indicate a loading state.

Full Width

The fullWidth prop can be used to make the text input full width.

With Hint

The hint prop can be used to create a prop for the description of the input. This props sets the aria-describedby attribute to a random generated id. The hint appears below the input.

Disabled

Required

Read Only

Invalid

Uncontrolled

TextInput can be used in an uncontrolled way by utilising the <form/> html component. The following form will automatically submit using the url params. If you press "submit" you can see the params in the URL change based on the off/on state of the input.

Auto Focus

The autoFocus prop is an attribute for indicating that an element should be focused on page load, or when the element appears on the DOM. Refresh the page to trigger autoFocus.

API

PropTypeDefaultDescription
autoFocusbooleanfalseWhether the element should receive focus on render. @extends jsdoc from AriaTextFieldProps[autoFocus]
classes{ root?: string; label?: string; input?: string; hint?: string; error?: string; }—
data-testidstring—Data attribute for E2E testing purposes
disabledbooleanfalseWhether the input is disabled.
endAddonReactNode—The component or element to be placed inside the end of the input. __Note:__ loading spinner will always appear before this element.
fullWidthboolean—Whether the input is full width
hintReactNode—A description for the field. Provides a hint such as specific requirements for what to choose. @extends jsdoc from AriaTextFieldProps[description]
inputPropsInputHTMLAttributes<HTMLInputElement>—HTML attributes to pass to the underlying input element
invalidbooleanfalseWhether the input is invalid
labelPropsLabelHTMLAttributes<HTMLLabelElement>—HTML attributes to pass to the underlying label element
loadingboolean—Indicate loading state
readonlybooleanfalseWhether the input can be selected but not changed by the user.
requiredbooleanfalseWhether user input is required on the input before form submission. Often paired with the `necessityIndicator` prop to add a visual indicator to the input.
startAddonReactNode—The component or element to be placed inside the start of the input.
valuestring—Use React.useState to control this prop. Needs to be used with an event handler such as `onChange`. The current value (controlled). @extends jsdoc from AriaTextFieldProps[value]