Skip to main content
PROYECTOVIVIANA

NumberField

NumberFields allow users to enter and adjust numeric values with increment and decrement controls. They support range constraints, step values, and locale-aware formatting.

Import

import { NumberField } from '@proyecto-viviana/solid-spectrum';

Basic Usage

A simple number input with a label and stepper buttons.

<NumberField label="Quantity" defaultValue={1} />

Controlled Value

Control the number field value with state. The stepper buttons and keyboard input both update the controlled value.

Current quantity: 1

const [quantity, setQuantity] = createSignal(1);

<NumberField
  label="Items"
  value={quantity()}
  onChange={setQuantity}
/>
<p>Current quantity: {quantity()}</p>

With Min and Max

Constrain the value within a minimum and maximum range. The stepper buttons disable at boundaries.

<NumberField
  label="Age"
  minValue={0}
  maxValue={120}
  defaultValue={25}
/>
<NumberField
  label="Rating (1-5)"
  minValue={1}
  maxValue={5}
  defaultValue={3}
/>

Step Values

Configure the increment/decrement step size for fine or coarse adjustments.

<NumberField
  label="Opacity"
  minValue={0}
  maxValue={1}
  step={0.1}
  defaultValue={0.5}
/>
<NumberField
  label="Quantity (step 5)"
  step={5}
  defaultValue={10}
/>

Currency Formatting

Use formatOptions to display values with locale-aware currency formatting.

Raw value: 29.99

const [price, setPrice] = createSignal(29.99);

<NumberField
  label="Price"
  value={price()}
  onChange={setPrice}
  formatOptions={{
    style: 'currency',
    currency: 'USD',
  }}
/>

Percentage Formatting

Display values as percentages. The underlying value is stored as a decimal (0-1).

<NumberField
  label="Discount"
  defaultValue={0.15}
  minValue={0}
  maxValue={1}
  step={0.01}
  formatOptions={{
    style: 'percent',
  }}
/>

Sizes

NumberField supports S, M, L, and XL sizes.

<NumberField label="Small" size="S" defaultValue={5} />
<NumberField label="Medium" size="M" defaultValue={10} />
<NumberField label="Large" size="L" defaultValue={15} />
<NumberField label="Extra large" size="XL" defaultValue={20} />

Hidden Stepper

Hide the increment/decrement buttons for a cleaner appearance. Users can still type values directly and use arrow keys.

<NumberField
  label="Score"
  hideStepper
  defaultValue={85}
/>

Disabled and Invalid

NumberField supports disabled and invalid states for form integration.

Value must be between 1 and 100
<NumberField label="Disabled" isDisabled defaultValue={42} />
<NumberField
  label="Invalid"
  isInvalid
  errorMessage="Value must be between 1 and 100"
  defaultValue={150}
  maxValue={100}
/>

Props

PropTypeDefaultDescription
labelstringLabel text for the number field (required for accessibility)
valuenumberThe current value (controlled)
defaultValuenumberThe default value (uncontrolled)
onChange(value: number) => voidHandler called when the value changes
minValuenumberThe minimum allowed value
maxValuenumberThe maximum allowed value
stepnumber1The increment/decrement step size
formatOptionsIntl.NumberFormatOptionsOptions for locale-aware number formatting (e.g., currency, percent)
size'sm' | 'md' | 'lg''md'The size of the number field
variant'outline' | 'filled''outline'Visual style variant
isDisabledbooleanfalseWhether the number field is disabled
isRequiredbooleanfalseWhether the number field is required
isInvalidbooleanfalseWhether the number field is in an invalid state
errorMessagestringError message displayed when the field is invalid
descriptionstringHelp text displayed below the input
hideStepperbooleanfalseWhether to hide the increment/decrement stepper buttons

Accessibility

  • Uses role="spinbutton" with aria-valuenow, aria-valuemin, and aria-valuemax for screen readers
  • Label is associated with the input via aria-labelledby
  • Increment and decrement buttons have aria-label for screen readers
  • Supports keyboard interaction: Arrow Up/Down to increment/decrement, Home/End for min/max
  • Stepper buttons are automatically disabled at min/max boundaries
  • Invalid state is communicated via aria-invalid and linked error message
  • Description text is linked via aria-describedby