PeakUI

NumberField

Numeric input with stepper buttons

Usage

import {NumberField} from "@peakui/react";

Anatomy

<NumberField>
  <Label>Width</Label>
  <NumberField.Group>
    <NumberField.DecrementButton />
    <NumberField.Input />
    <NumberField.IncrementButton />
  </NumberField.Group>
</NumberField>

Examples

Variants

Step

Controlled

Format Options

Customization

Tailwind CSS

<NumberField.Input className="w-[200px]" />

Global CSS

.number-field__input {
  min-width: 8rem;
}

Styling Reference

CSS Classes

ClassDescription
.number-fieldThe field wrapper element
.number-field--primary, .number-field--secondaryVariant modifiers
.number-field--full-widthFull-width modifier
.number-field__groupThe stepper group element
.number-field__group--full-widthGroup full-width modifier
.number-field__inputThe input element
.number-field__increment-buttonThe increment button
.number-field__decrement-buttonThe decrement button

Slots

SlotDescription
[data-slot="number-field"]The field wrapper element
[data-slot="number-field-group"]The stepper group element
[data-slot="number-field-input"]The input element
[data-slot="number-field-increment-button"]The increment button element
[data-slot="number-field-increment-button-icon"]The default plus glyph
[data-slot="number-field-decrement-button"]The decrement button element
[data-slot="number-field-decrement-button-icon"]The default minus glyph

Interactive States

The component supports both CSS pseudo-classes and data attributes:

StateAttribute
Focused[data-focus-visible="true"] / :focus-visible
Hovered[data-hovered="true"]
Pressed[data-pressed="true"]
Disabled[data-disabled="true"]
Invalid[data-invalid="true"]
Stepper disabled (at bounds)[data-disabled="true"] on the button

API Reference

NumberField.Root

PropTypeDefaultDescription
variant"primary" | "secondary""primary"Visual variant
fullWidthbooleanfalseStretches the group to the container width
valuenumber-Controlled value
defaultValuenumber-Uncontrolled initial value
minValuenumber-Lower bound
maxValuenumber-Upper bound
stepnumber-Increment size
formatOptionsIntl.NumberFormatOptions-Locale-aware formatting
isDisabledboolean-Disables the field
isReadOnlyboolean-Makes the field read-only
isRequiredboolean-Marks the field required
isInvalidboolean-Marks the field invalid
validate(value) => boolean | string-Validation function
onChange(value: number) => void-Called when the value changes
...restEvery React Aria NumberField attribute is accepted

The input renders a textbox with aria-roledescription="Number field" — React Aria's current pattern — and holds its value as a string.

NumberField.Group

PropTypeDefaultDescription
renderDOMRenderFunction<'div', GroupRenderProps>-Replaces the rendered element
...restEvery React Aria Group attribute is accepted

NumberField.Input

PropTypeDefaultDescription
...restEvery React Aria Input attribute is accepted

NumberField.IncrementButton

PropTypeDefaultDescription
childrenReactNodeplus glyphReplaces the default icon when a valid element
...restEvery React Aria Button attribute is accepted

NumberField.DecrementButton

PropTypeDefaultDescription
childrenReactNodeminus glyphReplaces the default icon when a valid element
...restEvery React Aria Button attribute is accepted

Render Props

children and className of NumberField.Root and NumberField.Group accept a function receiving the respective React Aria render props.

On this page