<script> import {NumberInput, Field} from 'ui-ingredients'; import {ChevronDownIcon, ChevronUpIcon} from '$lib/icons';</script><Field.Root> <NumberInput.Root> <NumberInput.Label>Label</NumberInput.Label> <NumberInput.Control> <NumberInput.Input /> <NumberInput.IncrementTrigger> <ChevronUpIcon /> </NumberInput.IncrementTrigger> <NumberInput.DecrementTrigger> <ChevronDownIcon /> </NumberInput.DecrementTrigger> </NumberInput.Control> </NumberInput.Root> <Field.HelperText>This is a helper text</Field.HelperText> <Field.ErrorText>This is an error text</Field.ErrorText></Field.Root>
API Reference
Root
Prop
Default
Description
allowMouseWheel
booleanWhether to allow mouse wheel to change the value
allowOverflow
true
booleanWhether to allow the value overflow the min/max range
clampValueOnBlur
true
booleanWhether to clamp the value when the input loses focus (blur)
defaultValue
stringThe initial value of the input when rendered.
Use when you don't need to control the value of the input.
disabled
booleanWhether the number input is disabled.
focusInputOnChange
true
booleanWhether to focus input when the value changes
form
stringThe associate form of the input element.
formatOptions
Intl.NumberFormatOptionsThe options to pass to the `Intl.NumberFormat` constructor
id
stringThe unique identifier of the machine.
ids
{
root?: string;
label?: string;
input?: string;
incrementTrigger?: string;
decrementTrigger?: string;
scrubber?: string;
}The ids of the elements in the number input. Useful for composition.
inputMode
"decimal"
InputModeHints at the type of data that might be entered by the user. It also determines
the type of keyboard shown to the user on mobile devices
invalid
booleanWhether the number input value is invalid.
locale
"en-US"
stringThe current locale. Based on the BCP 47 definition.
max
Number.MAX_SAFE_INTEGER
numberThe maximum value of the number input
min
Number.MIN_SAFE_INTEGER
numberThe minimum value of the number input
name
stringThe name attribute of the number input. Useful for form submission.
onFocusChange
(details: FocusChangeDetails) => voidFunction invoked when the number input is focused
onValueChange
(details: ValueChangeDetails) => voidFunction invoked when the value changes
onValueInvalid
(details: ValueInvalidDetails) => voidFunction invoked when the value overflows or underflows the min/max range
pattern
"[0-9]*(.[0-9]+)?"
stringThe pattern used to check the <input> element's value against
readOnly
booleanWhether the number input is readonly
required
booleanWhether the number input is required
spinOnPress
true
booleanWhether to spin the value when the increment/decrement button is pressed
step
1
numberThe amount to increment or decrement the value by
translations
IntlTranslationsSpecifies the localized strings that identifies the accessibility elements and their states
value
stringThe controlled value of the input
asChild
SnippetRender a different element.
Data Attribute
Value
data-disabled
Present when disabled
data-focus
Present when focused
data-invalid
Present when invalid
data-part
root
data-scope
number-input
Control
Prop
Default
Description
asChild
SnippetRender a different element.
Data Attribute
Value
data-disabled
Present when disabled
data-focus
Present when focused
data-invalid
Present when invalid
data-part
control
data-scope
number-input
DecrementTrigger
Prop
Default
Description
asChild
SnippetRender a different element.
Data Attribute
Value
data-disabled
Present when disabled
data-part
decrement-trigger
data-scope
number-input
IncrementTrigger
Prop
Default
Description
asChild
SnippetRender a different element.
Data Attribute
Value
data-disabled
Present when disabled
data-part
increment-trigger
data-scope
number-input
Input
Prop
Default
Description
asChild
SnippetRender a different element.
Data Attribute
Value
data-disabled
Present when disabled
data-invalid
Present when invalid
data-part
input
data-scope
number-input
Label
Prop
Default
Description
asChild
SnippetRender a different element.
Data Attribute
Value
data-disabled
Present when disabled
data-focus
Present when focused
data-invalid
Present when invalid
data-part
label
data-scope
number-input
Scrubber
Prop
Default
Description
asChild
SnippetRender a different element.
Data Attribute
Value
data-disabled
Present when disabled
data-part
scrubber
data-scope
number-input
ValueText
Prop
Default
Description
asChild
SnippetRender a different element.
Data Attribute
Value
data-disabled
Present when disabled
data-focus
Present when focused
data-invalid
Present when invalid
data-part
value-text
data-scope
number-input
Accessibility
Keyboard Support
Key
Description
ArrowUp
Increments the value of the number input by a predefined step.
ArrowDown
Decrements the value of the number input by a predefined step.
PageUp
Increments the value of the number input by a larger predefined step.
PageDown
Decrements the value of the number input by a larger predefined step.
Home
Sets the value of the number input to its minimum allowed value.
End
Sets the value of the number input to its maximum allowed value.