PXD

Number Input

Input box for entering numbers only.

Default

<script setup>
import { ref } from 'vue'

const number = ref(0)
</script>

<template>
  <PNumberInput v-model="number" class="max-w-xs" />
</template>

Sizes

<script setup>
import { ref } from 'vue'

const value = ref(1)
</script>

<template>
  <PStack direction="vertical">
    <PNumberInput v-model="value" size="sm" class="max-w-xs" />
    <PNumberInput v-model="value" size="md" class="max-w-xs" />
    <PNumberInput v-model="value" size="lg" class="max-w-xs" />
  </PStack>
</template>

Disabled

<script setup>
import { ref } from 'vue'

const value = ref(2)
</script>

<template>
  <PNumberInput v-model="value" disabled class="max-w-xs" />
</template>

Step

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PNumberInput v-model="value" :step="2" class="max-w-xs" />
</template>

Max/Min

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PNumberInput v-model="value" :min="0" :max="10" class="max-w-xs" />
</template>

Precision

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PNumberInput v-model="value" :precision="2" :step="0.68" class="max-w-xs" />
</template>

Thousands format

<script setup>
import { ref } from 'vue'

const value = ref(10000)
</script>

<template>
  <PStack direction="vertical">
    <PNumberInput v-model="value" thousands class="max-w-xs" />
    <PNumberInput v-model="value" thousands thousands-separator="_" class="max-w-xs" />
  </PStack>
</template>

No controls

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PNumberInput v-model="value" :controls="false" class="max-w-xs" />
</template>

Icons

<script setup>
import { ref } from 'vue'
import PlusCircleIcon from '@gdsicon/vue/plus-circle'
import MinusCircleIcon from '@gdsicon/vue/minus-circle'

const value = ref(0)
</script>

<template>
  <PNumberInput v-model="value" class="max-w-xs">
    <template #minusIcon>
      <MinusCircleIcon />
    </template>

    <template #plusIcon>
      <PlusCircleIcon />
    </template>
  </PNumberInput>
</template>

Prefix and Suffix

<script setup>
import { ref } from 'vue'

const value = ref(0)
</script>

<template>
  <PNumberInput v-model="value" class="max-w-xs">
    <template #prefix>
      <span class="pl-2">¥</span>
    </template>

    <template #suffix>
      <span class="pr-2">RMB</span>
    </template>
  </PNumberInput>
</template>

Props

NameTypeDefaultDescription
minnumberNumber.MIN_SAFE_INTEGERLowest value the control accepts
maxnumberNumber.MAX_SAFE_INTEGERHighest value the control accepts
stepnumber1Amount added or removed per step, also drives ArrowUp and ArrowDown
readonlyboolean-Accept focus but block editing and the step controls
disabledboolean-Block all interaction and grey out the control
controlsbooleantrueShow the plus and minus buttons
precisionnumber-Fixed number of decimal places, inferred from step when omitted
thousandsboolean-Group the integer part with the separator while the input is not focused
thousands-separatorstring','Character placed between each group of three digits
scientificbooleantrueAllow e and E so users can type scientific notation
clear-valuenumber | nullnullValue restored by the built-in clear button
model-valuenumber | null-Current value, null when the field is empty

Events

NameTypeDescription
blur(event: FocusEvent) => voidEmitted when the input loses focus, after the value has been clamped back into range.
focus(event: FocusEvent) => voidEmitted when the input gains focus.
change(value: number | null, event: Event) => voidEmitted when the inner input reports a committed change, on blur after an edit, on Enter, or when the clear button is used.
update:modelValue(value: number | null) => voidEmitted whenever the component writes a new value, from typing, the step controls, the arrow keys, or blur clamping.

Slots

NameDescription
minusIconminusIcon slot
plusIconplusIcon slot
prefixPrefix slot
suffixSuffix slot

Source

Source