Skip to main content

Number Input

A numeric input component with increment and decrement controls.

Features

Installation

typo3 ui:add number-input

Read more about installing Components and Primitives.

Examples

With Min/Max Constraints

Pass the min prop or max prop to set an upper and lower limit for the input. By default, the input will restrict the value to stay within the specified range.

With Format Options

You can format the input value to be rounded to specific decimal points or to be displayed as a currency by passing an object in shape of Intl.NumberFormatOptions. Note that this is a client-only API so the initial value rendered on the server will not be formatted.

With Scrubber

The scrubber allows users to change the value by clicking and dragging horizontally.

Mouse Wheel Support

Enable changing the value with the mouse wheel when the input is focused.

Localization

Default increment and decrement labels are shipped via XLF and follow the current Site Language. For per-template overrides, pass translated strings through the translations prop. Set a translation entry to {false} or an empty string to omit the corresponding aria-label.

<f:variable
    name="numberInputTranslations"
    value="{
        incrementLabel: '{f:translate(key: \'LLL:EXT:site_package/Resources/Private/Language/locallang.xlf:forms.quantity.increase\')}',
        decrementLabel: '{f:translate(key: \'LLL:EXT:site_package/Resources/Private/Language/locallang.xlf:forms.quantity.decrease\')}'
    }"
/>

<ui:numberInput.root translations="{numberInputTranslations}"> ... </ui:numberInput.root>

API Reference

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

numberInput.root

Provides shared number input state and wraps all related parts. Renders a <div> element.

NameDescriptionRequiredDefault
disabledboolean
Whether the number input is disabled. Inherited from a surrounding field when available.
No
-
invalidboolean
Whether the number input value is invalid. Inherited from a surrounding field when available.
No
-
requiredboolean
Whether the number input is required. Inherited from a surrounding field when available.
No
-
readOnlyboolean
Whether the number input is readonly. Inherited from a surrounding field when available.
No
-
namestring
The name attribute of the number input. Useful for form submission. Inherited from a surrounding field when available.
No
-
formstring
The associate form of the input element.
No
-
defaultValuestring
The initial value of the input when rendered. Use when you don't need to control the value of the input. Inherited from a surrounding field when available.
No
''
minfloat
The minimum value of the number input.
No
-
maxfloat
The maximum value of the number input.
No
-
stepfloat
The amount to increment or decrement the value by.
No
-
allowMouseWheelboolean
Whether to allow mouse wheel to change the value.
No
-
allowOverflowboolean
Whether to allow the value overflow the min/max range.
No
false
clampValueOnBlurboolean
Whether to clamp the value when the input loses focus (blur).
No
true
focusInputOnChangeboolean
Whether to focus input when the value changes.
No
true
spinOnPressboolean
Whether to spin the value when the increment/decrement button is pressed.
No
true
formatOptionsarray
The options to pass to the `Intl.NumberFormat` constructor.
No
-
inputModestring
Hints at the type of data that might be entered by the user and the keyboard shown on mobile devices.
No
'decimal'
patternstring
The pattern used to check the `<input>` element's value against.
No
'-?[0-9]*(.[0-9]+)?'
translationsarray
Specifies the localized strings that identify the accessibility elements and their states. Use `f:translate` for per-template localization overrides when needed.
No
-
localestring
The current locale. Inherited from the site's language.
No
-

numberInput.label

Labels the number input. Renders a <label> element.

numberInput.control

Groups the input and stepper triggers. Renders a <div> element.

numberInput.input

Provides the editable spinbutton input. Renders an <input> element.

numberInput.incrementTrigger

Increases the current value. Renders a <button> element.

numberInput.decrementTrigger

Decreases the current value. Renders a <button> element.

numberInput.scrubber

Allows changing the value by dragging. Renders a <div> element.

numberInput.valueText

Displays the formatted value as text. Renders a <span> element.

Anatomy

<primitives:numberInput.root>
    <primitives:numberInput.label />
    <primitives:numberInput.control>
        <primitives:numberInput.decrementTrigger />
        <primitives:numberInput.input />
        <primitives:numberInput.incrementTrigger />
    </primitives:numberInput.control>
    <primitives:numberInput.scrubber />
    <primitives:numberInput.valueText />
</primitives:numberInput.root>