Number Field
A number field allows a user to enter a number and increment or decrement the value using stepper buttons.
Preview
Installation
npx sigma-ui@latest add number-fieldUsage
<script setup lang="ts">
import { ref } from 'vue';
import {
NumberField,
NumberFieldContent,
NumberFieldDecrement,
NumberFieldIncrement,
NumberFieldInput,
} from '@/components/ui/number-field';
const value = ref(18);
</script>
<template>
<NumberField
v-model="value"
:min="0"
>
<NumberFieldContent>
<NumberFieldDecrement />
<NumberFieldInput />
<NumberFieldIncrement />
</NumberFieldContent>
</NumberField>
</template>- Use
v-modelto control the value, ordefaultValueto set an initial value. min,max, andsteplimit the value and set the increment of the stepper buttons.formatOptionstakesIntl.NumberFormatoptions to format decimals, percentages, or currencies.
Examples
Disabled
Decimal
Percentage
Currency
Form
API Reference
NumberField
Props
| Prop | Type | Default |
|---|---|---|
defaultValue | number | - |
modelValue | number | null | - |
minThe smallest value allowed for the input. | number | - |
maxThe largest value allowed for the input. | number | - |
stepThe amount that the input value changes with each increment or decrement "tick". | number | - |
stepSnappingWhen | boolean | - |
allowInvalidWhen | boolean | - |
focusOnChangeWhen | boolean | - |
formatOptionsFormatting options for the value displayed in the number field. This also affects what characters are allowed to be typed by the user. | Intl.NumberFormatOptions | - |
localeThe locale to use for formatting and currencies | string | - |
disabledWhen | boolean | - |
readonlyWhen | boolean | - |
disableWheelChangeWhen | boolean | - |
invertWheelChangeWhen | boolean | - |
idId of the element | string | - |
startingValueThe value the first increment or decrement sets when the field is empty. It is clamped to | number | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValue | [val: number] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
NumberFieldInput
This component has no props, events, or slots.
NumberFieldIncrement
Props
| Prop | Type | Default |
|---|---|---|
disabled | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
NumberFieldDecrement
Props
| Prop | Type | Default |
|---|---|---|
disabled | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
NumberFieldContent
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Adheres to the Spinbutton WAI-ARIA design pattern. Reka UI handles the roles, ARIA attributes, and keyboard interactions.
| Key | Description |
|---|---|
| ArrowUp | Increases the value. |
| ArrowDown | Decreases the value. |
| PageUp | Increases the value by a scale of 10. |
| PageDown | Decreases the value by a scale of 10. |
| Home | Sets the value to the minimum, when min is set. |
| End | Sets the value to the maximum, when max is set. |
| Enter | Applies the typed value. |
| Tab | Moves focus to the next focusable element. |