GhostNumberInput
GhostNumberInput is a locale-aware numeric spinbutton with v-model, min / max / step, increment and decrement buttons, and clamping. Import it from @ghostvue/themes for the default visual treatment. To style the parts yourself, see Advanced: headless composition.
Bounded, currency-formatted, and disabled GhostNumberInput controls with live total.
The quota form pairs themed GhostNumberInput from @ghostvue/themes with GhostField: active seats clamp between 1 and 50, the spend cap formats as USD currency in $50 steps, and the disabled legacy quota scales its stepper buttons at size="sm".
Bounds and units
Seat and session-length limits with unit-formatted values, disabled steppers at the bound, and a limit message.
min and max are inclusive and set aria-valuemin / aria-valuemax. At a bound, the stepper button for that direction disables and the arrow keys stop. Home and End jump straight to min and max, and a typed value outside the range clamps on blur. Because the disabled button is the only visual cue, the booking card also says in words which limit was reached.
Session length formats with { style: 'unit', unit: 'minute', unitDisplay: 'long' }, so the field reads "90 minutes" and so does aria-valuetext. Seats need no unit: the label already says what the number counts.
Size and layout
Large block retry delay in seconds from @ghostvue/themes.
size scales the field and its stepper buttons, and block stretches the control to the width of its container. Without block, the control fits about eight digits in a toolbar or table cell and fills a GhostField; see form control widths. class and style go to a frame around the whole control, so an inline-size there sizes the field and its buttons together. Other attributes, such as id, name and aria-*, still reach the text input. The retry delay formats in seconds and names its buttons for the action they take.
@ghostvue/themes adds these to the headless GhostNumberInput API, which it forwards:
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | "md" | Control size. Default omits data-size. |
block | boolean | false | Fill the container's inline size via data-block. Without it the control fits about eight digits and fills a GhostField. |
Field integration
Bind the GhostFieldControl slot props to the spinbutton with v-bind, as the examples above do, so the field's label, description and invalid state reach the spinbutton itself rather than the stepper buttons.
Committing values
v-model emits update:modelValue when a value commits (blur after typing, Enter, buttons, or keyboard stepping). While typing, the draft text is local until commit.
Locale and format parsing contract
GhostNumberInput formats and round-trip parses Intl.NumberFormat outputs for notation: 'standard' (the default) across decimal, currency (including currencySign: 'accounting'), percent, and unit styles:
- Affixes and signs: Currency symbols/codes, unit labels, percent signs, accounting parentheses
(...),signDisplaymarkers, and Unicode bidi control characters are stripped based onIntl.NumberFormat.formatToParts. Drafts with or without the configured currency/unit/percent affixes parse to the same numeric model value. - Percent scaling: In
style: 'percent', both60%and plain60commit tomodelValue = 0.6(and submit0.6via the hidden form input). - Localized digits: Both the locale's
numberingSystemdigits (such as Eastern Arabic-Indic٠–٩or Persian۰–۹) and ASCII0–9are accepted. - Grouping: Locale group separators are optional, but when present they must match the locale's grouping sizes (for example,
1.234,5is valid inde-DE, while malformed grouping like1.5inde-DEis rejected and reverts to the last committed value). - Non-standard notations:
compact,scientific, andengineeringnotations are outside the editing contract and are not parsed.
To show a unit with the value, such as "30 seconds", use { style: 'unit', unit: 'second', unitDisplay: 'long' } rather than placing text beside the control. The formatted unit then appears in the field and in aria-valuetext. The input group recipe is for text inputs, not for GhostNumberInput.
Accessibility
Follows the WAI-ARIA spinbutton pattern. Arrow keys, Home, End, and Page Up/Down adjust the value while the spinbutton is focused. Tab targets the spinbutton only; buttons are pointer and programmatic accessories (tabindex="-1"). Give the buttons specific names with decrement-label and increment-label when a form has several spinbuttons.
Advanced: headless composition
For teams that bring their own design system, the headless GhostNumberInput from @ghostvue/vue renders the same spinbutton and buttons with no styles.
Basic use
Labeled spinbutton with min, max, and step.
The spinbutton is a text field with role="spinbutton". Pair it with a visible label (or aria-label / aria-labelledby). Native attributes fall through to the text field, not the surrounding buttons.
Headless bounds
Increment buttons disable at min and max.
Increment and decrement disable at min and max. Typed values clamp on blur.
GhostField
Currency formatting inside GhostField.
Bind GhostFieldControl slot props to the spinbutton input through v-bind.
Component refs
Programmatic increment through the exposed API.
The ref exposes element, focus, blur, increment, and decrement.
Styling hooks
- Root:
ghost-number-input,data-part="root", optionaldata-state - Input:
ghost-number-input__input,data-part="input" - Buttons:
ghost-number-input__button,data-part="decrement"|"increment"
API
| Prop | Type | Default | Description |
|---|---|---|---|
decrementLabel | string | "Decrease" | aria-label on the decrement button. |
defaultValue | null | number | null | Initial uncontrolled value and form-reset seed. |
disabled | boolean | false | Disables the field and buttons. |
formatOptions | Intl.NumberFormatOptions | — | Display and round-trip parse options (notation: 'standard'). |
incrementLabel | string | "Increase" | aria-label on the increment button. |
invalid | boolean | false | Sets aria-invalid on the spinbutton. |
locale | string | — | Intl.NumberFormat locale. |
max | number | — | Inclusive maximum (aria-valuemax). |
min | number | — | Inclusive minimum (aria-valuemin). |
modelValue | null | number | — | Controlled value. Omit for uncontrolled mode. null is empty. |
readonly | boolean | false | Focusable; edits and buttons do not change the value. |
required | boolean | false | Native required on the spinbutton. |
step | number | 1 | Step for buttons and arrow keys. |