Number Field

A number field component allows users to enter and adjust numeric values.

UsageCodeAccessibility
<sl-number-field aria-label="Number field" step-buttons="end" value="100"></sl-number-field>

When to use

Easily Adjust Values

The stepper control buttons allow users to increment or decrement the value is defined in steps, within a well-defined, preferably small, range. They are ideal for scenarios like adjusting product amounts, setting measurement values, or tuning numeric settings where direct typing might lead to errors.

Require Formatting Values

Number fields can display format-specific information, such as currency symbols or percentage signs, alongside the input value. This visual formatting helps users recognise the context of the data they enter, improving clarity and reducing mistakes, especially in financial or statistical inputs.

When not to use

For a Fixed Number of Options

When the selection involves a small, predefined set of numeric options, the Select component is more suitable than a number field. Select ensure quicker selection, avoid invalid entries, and streamline the user experience for limited choices.

Anatomy

ItemNameDescriptionOptional
1Input fieldArea where users type the number.No
2Stepper controlsField buttons to increment or decrement the value.Yes
3LabelText describing the purpose of the field.Yes
4Helper textTrxt that provides extra guidance.Yes
5PrefixText placed before the value.Yes
6SuffixText placed after the value.Yes
7Error messageCommunicates validation issues.Yes

Variants

  • Basic: Input field only.
  • Steppers: Input field plus increment/decrement controls.
  • Prefix or Suffix: Adds contextual information like currency or units.
  • Hint text: Provides additional instructions.
  • Validation: Shows error messages when input rules are not respected.

States

  • Default: Active field allowing free numerical input and adjustments.
  • Hover: Highlighted field indicating interactivity before clicking.
  • Active: Field focused and ready for user input.

Figma Options

With these options, you can tweak the appearance of the number field in Figma. They are available in the Design Panel so you can compose the tag to exactly fit the user experience need for the use case you are working on.

ItemOptionsDescription
Sizemd lgSize 'md' is the default size of the number field component
VariantDefault Invalid disabledIndicates the state of the number field
Stateidle hover active disabledIndicates the state of the number field
LabelvalueThe text of the label
PlaceholadervalueThe text of the placeholder
SteppersEnd EdgesDefine the place of the stepper buttons
Imput TextvalueThe text of the value
FocusOn OffShows the focus ring
PrefixOn OffShows the prefix of the field
SufixOn OffShows the sufix of the field

Behaviours

Keyboard Input

The number field accepts direct keyboard input, allowing users to quickly enter numerical values without relying on other controls.

Stepper Controls

Users can adjust the value easily using the increment and decrement buttons, ensuring fine-grained control over numerical input.

Input Validation

The field validates user input based on minimum, maximum, and step settings to maintain consistent and valid data.

Visual Formatting

The number field can apply visual formatting, such as thousand separators, to improve readability and reduce entry errors.

Accessibility Support

Built with accessibility in mind, the number field uses ARIA roles and supports full keyboard navigation, ensuring an inclusive user experience.

  • Text Field: If you want a free-form text input.
  • Select: Selecting from predefined numeric options.
Interactive example