Number Field
Enter a number or adjust it with increment and decrement buttons.
Demos
Size
Variant
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Installation
Complete the shared installation. Copy NumberField.vue and index.ts into app/components/ui/number-field/.
app/components/ui/number-field/NumberField.vue
<script setup lang="ts">
import { AlertDialog as Primitive } from 'akaza-ui'
import { computed, useAttrs, useTemplateRef } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
alertDialogVariants,
resolveAlertDialogVariants,
type AlertDialogProps,
type AlertDialogSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AlertDialogProps>(), {
as: undefined,
teleport: undefined,
transition: undefined,
duration: undefined,
title: undefined,
ariaLabel: undefined,
description: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AlertDialogSlots>()
const attrs = useAttrs()
const styles = computed(() => alertDialogVariants(resolveAlertDialogVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'content' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, width: _width, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
defineExpose({
get open() {
return primitive.value!.open
},
get close() {
return primitive.value!.close
},
get toggle() {
return primitive.value!.toggle
},
get titleId() {
return primitive.value!.titleId
},
get descriptionId() {
return primitive.value!.descriptionId
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AlertDialogSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
variant | outline, soft, bare | outline |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | field id | Input id. |
name | string | field name | Form field name. |
min | number | — | Minimum value. |
max | number | — | Maximum value. |
step | number | 1 | Increment/decrement step. |
placeholder | string | — | Native input placeholder. |
required | boolean | false | Required state. |
disabled | boolean | false | Disabled state. |
readonly | boolean | false | Read-only state. |
invalid | boolean | false | Sets invalid attrs. |
stepSnapping | boolean | true | Snap input/button values to the nearest step. |
disableWheelChange | boolean | false | Disables focused wheel stepping. |
invertWheelChange | boolean | false | Reverses wheel direction. |
focusOnChange | boolean | true | Focuses the input after button/scrub changes. |
scrubLabel | string | — | Renders a drag scrub area before the decrement button. |
scrubStep | number | step | Step used by scrub dragging. |
disableScrub | boolean | false | Disables scrub dragging. |
getValueLabel | (value) => string | undefined | — | Human-readable aria-valuetext. |
ariaLabel | string | — | Accessible label when no visible label exists. |
ariaDescribedby | string | field description/error | Accessible description ids. |
ui | NumberFieldUi | — | Classes for structural parts. |
Slots
| Slot | Props | Description |
|---|---|---|
scrub | value, isScrubbing | Custom scrub area content. |
decrement | value, decrement | Custom decrement button content. |
increment | value, increment | Custom increment button content. |
Events
| Event | Payload | Description |
|---|---|---|
value-change | (value, details) | Fired before model updates. details.cancel() prevents the update. |
value-commit | (value, details) | Fired on blur and after button, wheel, keyboard, or scrub interactions. |
Keyboard
| Key | Behavior |
|---|---|
ArrowUp / ArrowDown | Increment/decrement by step. |
PageUp / PageDown | Increment/decrement by step * 10. |
Home | Set to min when provided. |
End | Set to max when provided. |
Mouse wheel changes the value only while the input is focused. Set disableWheelChange to opt out.