Number Field

A specialized input for numeric values with increment/decrement controls.

Installation

Install the component package, shared coss-svelte theme, and Bits UI peer.

npm install coss-svelte @coss-svelte/theme bits-ui

Usage

Import the Svelte component exports directly from the package.

import { NumberField, NumberFieldDecrement, NumberFieldGroup, NumberFieldIncrement, NumberFieldInput, NumberFieldScrubArea } from "coss-svelte";

Anatomy

  • NumberField
  • NumberFieldDecrement
  • NumberFieldGroup
  • NumberFieldIncrement
  • NumberFieldInput
  • NumberFieldScrubArea

API Reference

NumberField

A specialized input for numeric values with increment/decrement controls.

Signatures

{ value?: number | null; onValueChange?: ((value: number | null, details: NumberFieldChangeDetails) => void); onValueCommit?: ((value: number | null, details: NumberFieldChangeDetails) => void) }
PropTypeDefaultDescription
bind:refHTMLDivElement | nullnullBindable reference to the owned root div.
defaultValuenumber | nullnullInitial value and the captured native form-reset baseline.
bind:valuenumber | nulldefaultValueCurrent finite numeric value. External writes are displayed without callbacks or silent clamping.
minnumber-Minimum value for the control.
maxnumber-Maximum value for the control.
stepnumber1Discrete increment for keys, buttons, wheel, and scrubbing; direct text is not snapped.
smallStepnumber0.1Fine-grained increment used by Alt+Arrow keys.
largeStepnumber10Increment used by PageUp/PageDown and Shift+Arrow keys.
localestring | string[]"en-US"Locale used for deterministic numeric parsing and formatting.
formatIntl.NumberFormatOptions{}Formats the committed display value with `Intl.NumberFormat`.
labelstring"Number" outside FieldVisible scrub label and accessible name; an enclosing Field label is used when omitted.
sizeNumberFieldSize"default"Size variant for the component.
idstring-ID forwarded to the form control.
namestring-Serializes the invariant numeric value through a hidden form control.
formstring-Associates the control with a form elsewhere in the document.
requiredbooleanfalseMarks the field or label as required.
disabledbooleanfalseDisables interaction with the control.
readonlybooleanfalseKeeps the input focusable while preventing value changes.
invalidbooleanfalseMarks the component invalid independently of parse validity.
allowWheelScrubbooleanfalseAllows focused wheel gestures to change the number.
onValueChange((value: number | null, details: NumberFieldChangeDetails) => void)-Runs after each accepted numeric value change with its reason, previous value, and source event.
onValueCommit((value: number | null, details: NumberFieldChangeDetails) => void)-Runs once when a semantic input, keyboard, pointer, wheel, scrub, or reset transaction commits.
children : Snippet<[]>bind:ref : HTMLDivElement | null

Inherits from Svelte <div> attributes.

NumberFieldDecrement

Decreases the shared value, including press-and-hold repetition and bound handling.

PropTypeDefaultDescription
bind:refHTMLButtonElement | nullnullBindable reference to the decrement button.
children : Snippet<[]>bind:ref : HTMLButtonElement | null

Inherits from Svelte <button> attributes.

NumberFieldGroup

Groups the input and step controls into one focus-ring and validation surface.

PropTypeDefaultDescription
bind:refHTMLDivElement | nullnullBindable reference to the presentational group div.
children : Snippet<[]>bind:ref : HTMLDivElement | null

Inherits from Svelte <div> attributes.

NumberFieldIncrement

Increases the shared value, including press-and-hold repetition and bound handling.

PropTypeDefaultDescription
bind:refHTMLButtonElement | nullnullBindable reference to the increment button.
children : Snippet<[]>bind:ref : HTMLButtonElement | null

Inherits from Svelte <button> attributes.

NumberFieldInput

Renders the locale-aware text input with accessible spinbutton semantics.

PropTypeDefaultDescription
bind:refHTMLInputElement | nullnullBindable reference to the visible spinbutton input.
bind:ref : HTMLInputElement | null

Inherits from Svelte <input> attributes.

NumberFieldScrubArea

Labels the input and supports horizontal pointer scrubbing on fine pointers.

PropTypeDefaultDescription
labelstring-Required non-empty accessible label; custom children replace only its visual contents.
bind:refHTMLDivElement | nullnullBindable reference to the scrub-area wrapper.
children : Snippet<[]>bind:ref : HTMLDivElement | null

Inherits from Svelte <div> attributes.

Implementation Details

Status
Stable
Foundation
custom
Category
Selection & Input
Particles
11