Skip to content

Input Number

Input numerical values with a customizable range.

Basic usage

Bind a variable to v-model in m-input-number element and you are set.

When inputting invalid string to the input box, input value will emit NaN to the upper layer as result of error
vue
<script setup>
  import { ref } from 'vue'

  const num = ref(1)
  const handleChange = (value) => {
    console.log(value)
  }
</script>

<template>
  <m-input-number v-model="num" :min="1" :max="10" @change="handleChange" />
</template>

Disabled

The disabled attribute accepts a boolean, and if the value is true, the component is disabled. If you just need to control the value within a range, you can add min attribute to set the minimum value and max to set the maximum value. By default, the minimum value is 0.

vue
<template>
  <m-input-number v-model="num" :disabled="true" />
</template>

Steps

Allows you to define incremental steps.

Add step attribute to set the step.

vue
<template>
  <m-input-number v-model="num" :step="2" />
</template>

Precision

Add precision attribute to set the precision of input value.

vue
<template>
  <m-input-number v-model="num" :precision="2" :step="0.1" :max="10" />
</template>
The value of `precision` must be a non negative integer and should not be less than the decimal places of step.

Size

Use attribute size to set additional sizes with large or small.

vue
<template>
<m-input-number v-model="num" size="large" />
<m-input-number v-model="num" size="small" />
<m-input-number v-model="num" size="mini" />
</template>

Controls Position

Set controls-position to decide the position of control buttons.

vue
<template>
<m-input-number v-model="num" controls-position="right" />
</template>

Custom Icon

Use decreaseIcon and increaseIcon to set custom icons.

vue
<template>
<m-input-number v-model="num" controls-position="right" >
  <template #decreaseIcon >
    <m-icon name="close"></m-icon>
  </template>
</m-input-number>
</template>

API

PropertyDescriptionTypeDefault
v-modelBinding valuestring-
valueBinding valuestring-
placeholderPlaceholder textstring-
disabledDisabled state of input boxbooleanfalse
readonlyReadonly state of input boxbooleanfalse
sizeSize of input box, optional values: minismalllargestringsmall
prefixPrefix slotstring-
suffixSuffix slotstring-
minMinimum allowed valuenumber-
maxMaximum allowed valuenumber-

Events

Event NameDescriptionParameters
changeTriggered when the value changes(value: string)
focusTriggered when the input box gets focus(event: Event)
blurTriggered when the input box loses focus(event: Event)

Slots

NameDescription
prefixPrefix slot
suffixSuffix slot
decreaseIconCustom icon for decreasing button
increaseIconCustom icon for increasing button

Released under the MIT License.