On this page

Number field

Install, props and the parts Number field is built from.

Install

Run this in the app, after shadcn-vue init and the Beehexa theme (Button › Code):

npx shadcn-vue@latest add https://beehexa.design/r/number-field.json

Use

<script setup lang="ts">
import { ref } from 'vue'
import {
  NumberField, NumberFieldContent, NumberFieldDecrement, NumberFieldIncrement, NumberFieldInput,
} from '@/components/ui/number-field'

const quantity = ref(12)
</script>

<template>
  <NumberField id="stock-quantity" v-model="quantity" :min="0">
    <label for="stock-quantity">Stock quantity</label>
    <NumberFieldContent>
      <NumberFieldDecrement />
      <NumberFieldInput />
      <NumberFieldIncrement />
    </NumberFieldContent>
  </NumberField>
</template>

Props

Part Prop Values Notes
NumberField v-model, defaultValue number
NumberField min, max, step number The buttons and keys stay inside the limits
NumberField formatOptions, locale Intl.NumberFormat options, a locale Currency, percent, decimals
NumberField id string Goes to the input, for <label for>
NumberField disabled, readonly, required, name
NumberFieldInput aria-invalid, aria-describedby Red edge and the error message
NumberFieldDecrement, NumberFieldIncrement aria-label string Defaults to “Decrease” and “Increase”; translate them

Built on

Wraps the reka-ui NumberField with the shadcn-vue NumberField API. reka-ui gives the spinbutton role with aria-valuenow, aria-valuemin and aria-valuemax, the keys, number parsing and formatting per locale. Beehexa adds the field and button styles.