<BaseInputNumber /> · An incremental number input.
<template>
<BaseInputNumber
v-model="value"
rounded="sm"
placeholder="Quantity"
/>
</template>
<script setup lang="ts">
const value = ref(0)
</script>
This component is self closing and can be used to create a number input. You can customize the input's visual style by using the available props.
<template>
<BaseInputNumber />
</template>
This component has props that you can use to modify its visual style and behavior.
| Model | Type |
|---|---|
model-value | number | null |
| Prop | Type |
|---|---|
inputmodedefault: - | "numeric" | "decimal"The inputmode to use for the input, usually for mobile devices. |
placeholderdefault: - | stringThe placeholder to display for the input. |
variantdefault: "default" | "default" | "muted"The contrast of the input. |
roundeddefault: "md" | "none" | "md" | "sm" | "lg" | "full"The radius of the input. |
sizedefault: "md" | "md" | "sm" | "lg" | "xl"The size of the input. |
classesdefault: {} | { root?: string | string[]; button?: string | string[]; buttonWrapper?: string | string[]; }Optional classes to pass to the inner components. |
default-valuedefault: - | number |
mindefault: - | numberThe smallest value allowed for the input. |
maxdefault: - | numberThe largest value allowed for the input. |
stepdefault: - | numberThe amount that the input value changes with each increment or decrement "tick". |
step-snappingdefault: - | booleanWhen `false`, prevents the value from snapping to the nearest increment of the step value |
format-optionsdefault: - | NumberFormatOptionsFormatting options for the value displayed in the number field. This also affects what characters are allowed to be typed by the user. |
localedefault: - | stringThe locale to use for formatting dates |
disableddefault: - | booleanWhen `true`, prevents the user from interacting with the Number Field. |
disable-wheel-changedefault: - | booleanWhen `true`, prevents the value from changing on wheel scroll. |
iddefault: - | stringId of the element |
as-childdefault: - | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
asdefault: - | AsTag | ComponentThe element or component this component should render as. Can be overwritten by `asChild`. |
namedefault: - | stringThe name of the field. Submitted with its owning form as part of a name/value pair. |
requireddefault: - | booleanWhen `true`, indicates that the user must set the value before the owning form can be submitted. |
Your can override the component default CSS variables in your main.css file.
@theme {
/* Default input variables */
--color-input-default-border: var(--color-muted-300);
--color-input-default-bg: var(--color-white);
--color-input-default-text: var(--color-muted-600);
--color-input-default-placeholder: var(--color-muted-300);
--color-input-default-button-bg: var(--color-muted-100);
--color-input-default-button-bg-active: var(--color-muted-200);
--color-input-default-button-text: var(--color-muted-700);
/* Muted input variables */
--color-input-muted-border: var(--color-muted-300);
--color-input-muted-bg: var(--color-muted-50);
--color-input-muted-text: var(--color-muted-600);
--color-input-muted-placeholder: var(--color-muted-300);
--color-input-muted-button-bg: var(--color-muted-200);
--color-input-muted-button-bg-active: var(--color-muted-300);
--color-input-muted-button-text: var(--color-muted-700);
}
Use the size prop to change the size of the input.
<template>
<BaseInputNumber
v-model="value"
size="md"
placeholder="Size: md"
/>
</template>
<script setup lang="ts">
const value = ref(0)
</script>
Use the variant prop to change the visual style of the input.
<template>
<BaseInputNumber
v-model="value"
variant="default"
placeholder="Quantity"
/>
<BaseInputNumber
v-model="value"
variant="muted"
placeholder="Quantity"
/>
</template>
<script setup lang="ts">
const value = ref(0)
</script>
Use the rounded prop to change the border radius of the input.
<template>
<BaseInputNumber
v-model="value"
rounded="full"
placeholder="Quantity"
/>
</template>
<script setup lang="ts">
const value = ref(0)
</script>
Use the step prop to handle the incremental steps of the input.
<template>
<BaseInputNumber
v-model="fields.first"
rounded="md"
placeholder="Temperature (°C)"
:min="-20"
:max="20"
:step="0.05"
/>
<BaseInputNumber
v-model="fields.second"
rounded="md"
placeholder="Temperature (°F)"
:min="0"
:step="0.5"
/>
<BaseInputNumber
v-model="fields.third"
rounded="md"
placeholder="BTC"
:min="0"
:step="0.000001"
/>
<BaseInputNumber
v-model="fields.fourth"
rounded="md"
placeholder="Bytes"
:min="0"
:step="1024"
/>
</template>
const fields = reactive({
first: 0.15,
second: 1.5,
third: 1.542312,
fourth: 1024,
})
Use the disabled prop to set the input in a disabled state.
<template>
<BaseInputNumber
v-model="value"
placeholder="Quantity"
disabled
/>
</template>
<script setup lang="ts">
const value = ref(0)
</script>