NumberInput
Numbers, with room to edit.
Added in alpha.7
Available in Mavis 0.1.0-alpha.7.
<m-number-input v-model="quantity" label="Quantity" :min="1" :max="8" />Incomplete text stays in the editor without publishing an invalid number. Grouping, exponent notation and currency are not accepted. Uses JavaScript numbers, not a financial decimal type. Public focus() and blur() methods.
| Property | Type | Default | Description |
|---|---|---|---|
modelValue / v-model | number / null | null | Valid number controlled by the app. |
draft / v-model:draft | string | — | Optional draft, including incomplete text. |
label | string | required | Required visible label. |
min / max | number | — | Inclusive bounds. |
step | number | 1 | Positive button and Web arrow-key increment. |
locale | en-US / pt-BR | en-US | Decimal separator; grouping is not accepted. |
disabled / readonly | boolean | false | Blocks editing and stepping. |
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const value = ref<number | null>(2)
const draft = ref('2')
const disabled = ref(false)
</script>
<template>
<m-column gap="md">
<m-number-input
id="number-demo"
v-model="value"
v-model:draft="draft"
:label="pt ? 'Quantidade' : 'Quantity'"
:min="0"
:max="12"
:step="0.5"
:locale="pt ? 'pt-BR' : 'en-US'"
:incrementLabel="pt ? 'Aumentar' : 'Increase'"
:decrementLabel="pt ? 'Diminuir' : 'Decrease'"
:disabled="disabled"
/>
<m-text variant="caption" tone="muted">{{
pt
? `Valor: ${value ?? '—'} · Rascunho: ${draft}`
: `Value: ${value ?? '—'} · Draft: ${draft}`
}}</m-text>
<m-switch v-model="disabled" :label="pt ? 'Desabilitar' : 'Disable'" />
</m-column>
</template>The editor accepts . from decimal keyboards in both locales; pt-BR also accepts , and formats external values with it. Group separators are never inferred: 1.000 means one, not one thousand. Mixed separators are invalid.
update:modelValue emits valid numbers or null; update:draft follows the text. validityChange distinguishes valid, empty, incomplete, invalid and range. Use it to block submission while a draft is invalid: the numeric model still holds the last valid value. name names the Web form field. Public focus()/blur() forward to the editor; focus/blur events carry no platform objects.
Motion
Each step bumps the button that took it, whether it came from a tap or, on the Web, from an arrow key in the editor. An arrow key at min or max shakes the button whose way is closed, so the limit is felt without moving the editor you are typing in. The number in the editor never animates: it is an editable value and changes at once. Reduced motion keeps the bump and the shake still.
Desktop
On the desktop the field is the MInput editor with two stepper buttons beside it, and the up and down arrows step the value while the editor has the keyboard, inside min and max. name has no effect outside the browser; see Desktop components.