Skip to main content

Number Input

View as Markdown

A numeric input component with increment and decrement controls.

<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>
typo3 ui:add number-input

Read more about installing Components and Primitives.

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.

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.

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

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

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.

<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>

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.

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
-
smallStepfloat
The amount to increment or decrement the value by when the `Alt` key is held. Defaults to `step / 10`.
No
-
largeStepfloat
The amount to increment or decrement the value by when the `Shift` key is held. Defaults to `10 * step`.
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
-
inputModeEnum\NumberInputMode
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-number-input-root<uid>
data-disabledPresent when disabled
data-focusPresent when focused
data-invalidPresent when invalid
data-scrubbing

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-number-input-label<uid>
data-disabledPresent when disabled
data-focusPresent when focused
data-invalidPresent when invalid
data-requiredPresent when required
data-scrubbing

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-number-input-control<uid>
data-focusPresent when focused
data-disabledPresent when disabled
data-invalidPresent when invalid
data-scrubbing

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-number-input-input<uid>
data-invalidPresent when invalid
data-disabledPresent when disabled
data-scrubbing

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-number-input-increment-trigger<uid>
data-disabledPresent when disabled
data-scrubbing

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-number-input-decrement-trigger<uid>
data-disabledPresent when disabled
data-scrubbing

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-number-input-scrubber<uid>
data-disabledPresent when disabled
data-scrubbing

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

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-number-input-value-text<uid>
data-disabledPresent when disabled
data-invalidPresent when invalid
data-focusPresent when focused
data-scrubbing
NameTypeDescription
focusedbooleanWhether the input is focused.
scrubbingbooleanWhether the input is being scrubbed.
invalidbooleanWhether the input is invalid.
emptybooleanWhether the input value is empty.
valuestringThe formatted value of the input.
valueAsNumbernumberThe value of the input as a number.
setValue(value: number) => voidFunction to set the value of the input.
clearValueVoidFunctionFunction to clear the value of the input.
incrementVoidFunctionFunction to increment the value of the input by the step.
decrementVoidFunctionFunction to decrement the value of the input by the step.
setToMaxVoidFunctionFunction to set the value of the input to the max.
setToMinVoidFunctionFunction to set the value of the input to the min.
focusVoidFunctionFunction to focus the input.
getRootState() => RootStateReturns the state of the root.
getInputState() => InputStateReturns the state of the input.
getDecrementTriggerState() => DecrementTriggerStateReturns the state of the decrement trigger.
getIncrementTriggerState() => IncrementTriggerStateReturns the state of the increment trigger.
KeyDescription
ArrowUpIncrements the value of the number input by a predefined step.
ArrowDownDecrements the value of the number input by a predefined step.
Shift + ArrowUpIncrements the value of the number input by the `largeStep` amount.
Shift + ArrowDownDecrements the value of the number input by the `largeStep` amount.
Alt + ArrowUpIncrements the value of the number input by the `smallStep` amount.
Alt + ArrowDownDecrements the value of the number input by the `smallStep` amount.
HomeSets the value of the number input to its minimum allowed value.
EndSets the value of the number input to its maximum allowed value.
EnterSubmits the value entered in the number input.