Input

Also known as

Text Field, Text Box
Available since
@salt-ds/core@1.8.0

Input provides an editable field where users can enter text and numeric values. It works best for short, freeform content and data entry.

Density
Mode

Input comprises value text and a focus ring. The component is initially empty; once it has focus, it accepts text on a single line only.

The default variant for Input is "primary."

Input has a "secondary" variant.

For recommendations on variant choice, see the forms pattern.

You can disable the input, resulting in no action when the user interacts with it.

You can set Input to a read-only state. The user can't edit the value text in this state, but they can highlight and copy it.

By default, the marker is an em dash. If your application requires a different marker, you can set it via the emptyReadOnlyMarker prop.

  • Use the read-only state when the user needs the value for their flow or current task but cannot edit it, for example, because of user permissions.

You can use a placeholder to prompt user input if there's no default value.

Never use placeholder text to provide the user with contextual help since it will disappear when the user starts typing and doesn't meet minimum contrast requirements. Doing so is a WCAG failure.

Instead, use helper text beneath the field to provide instructions or directions necessary to complete the field, and reserve the placeholder text to support the help message, or provide an example of the suggested content.

You can find more information in the W3C form instructions.

Turn on automatic spellchecking using inputProps.

You can add custom adornments at the beginning or end of the Input field using the startAdornment and endAdornment props.

Start adornments typically describe the purpose of the field (e.g., a phone number input, or a currency), while end adornments typically indicate a reveal of more information (e.g., using an arrow icon) or to trigger a new user interface (such as a date picker).

You can use text and icons to add Salt styled alphanumeric text or symbols as adornments. Wrap multiple start or end adornments in a parent container and pass them to the respective prop as a single fragment. Adornments can be dynamic, with their value depending on the current state.

Note: Don't rely on static adornments for labelling, screen readers will not read them out.

You can use Button at the beginning or end of the input field with the startAdornment and endAdornment props. Buttons can allow for custom interactivity within the input field itself or elsewhere in the app via the input field.

Disable your interactive buttons or make them read-only should they match the state of the containing input field.

Input can show validation states (warning, success and error) with the prop validationStatus.

  • Use the error state to alert the user of a critical issue related to the input. This issue, which may jeopardize completion of the task, usually requires action from the user to resolve the error.
  • Display the warning state when you need to alert the user of a potential issue that won’t prevent them from continuing with a task but may cause errors if they don't address it.

Text has left alignment by default. Use the textAlign prop to change the alignment to “center” or “right.”

Numeric values often have right alignment to make comparing them easier. However, sometimes number fields don't relate to each other or mix with text fields in a form, so left alignment may promote better visual flow. Consider your use case when deciding on input field alignment.

You may choose to center-align an input field to bring emphasis to a value. However, this should be the exception, and you should use it sparingly.

To style Input with a full border, set bordered={true}.

We recommend this styling when the field uses the same fill color as the background (i.e., a primary fill color on a primary background).