Getting started

Actions

Forms

Layout

Navigation

Overlays

Feedback

Data display

Controllers

Helpers

Recipes

Number Field

Number fields wrap a native number input: the browser handles entry, min, max, step and the keyboard, with optional stepper buttons.

Try it

Usage

<rui-number-field> is a thin host around a native <input type="number">. The input owns the value, as a RuiInput's native input does: its value attribute is the server value, the default and reset value, and the step base when there is no min. The input keeps its name, min, max and step on the server and in the browser, and submits itself with its form. The browser validates the step grid (it starts at min), the range and a bad entry, shows the spin buttons and formats the number for the visitor's locale.

import { RuiNumberField } from '@ecopages/radiant-ui/number-field';

<RuiNumberField name="quantity" value={3} minValue={0} maxValue={10} step={1} label="Quantity" />

Set name, the bounds, step, disabled and readOnly on the host: it writes them to the input. The view writes value on its default input. The host keeps no copy of the value: host.value reads the input's number and writing it writes the input, so a number typed before the script loaded, a native reset and a stepper all read back as they are.

Stepper buttons

Compose RuiNumberFieldSteppers beside the input for styled buttons, and write value on the composed input. A press calls stepUp() or stepDown() on the input and dispatches input and change on it, and holding the button keeps stepping after half a second, so the buttons behave like the spin buttons. A touch steps when it lifts, or once held, so a scroll that starts on a button does not step, and stepping stops at a bound. Once rui-number-field is defined, a field that holds stepper buttons hides the native spin buttons, so it shows one set. Leave the stepper buttons out to keep the native ones.

import {
  RuiNumberField,
  RuiNumberFieldGroup,
  RuiNumberFieldInput,
  RuiNumberFieldDecrementButton,
  RuiNumberFieldIncrementButton,
  RuiNumberFieldSteppers,
} from '@ecopages/radiant-ui/number-field';

<RuiNumberField name="quantity" minValue={0} maxValue={10}>
  <RuiNumberFieldGroup>
    <RuiNumberFieldInput value={3} />
    <RuiNumberFieldSteppers>
      <RuiNumberFieldDecrementButton />
      <RuiNumberFieldIncrementButton />
    </RuiNumberFieldSteppers>
  </RuiNumberFieldGroup>
</RuiNumberField>

Custom markup

<rui-number-field> coordinates any light-DOM tree that matches its query contract. The RuiNumberField helpers stamp these targets; they are not required.

<rui-number-field name="quantity" min-value="0" max-value="10">
  <div class="rui-number-field__group" data-number-field-group>
    <input type="number" value="3" data-number-field-input data-rui-control data-rui-control-type="number" class="rui-number-field__input" />
    <button type="button" data-number-field-action="decrement" class="rui-number-field__stepper">−</button>
    <button type="button" data-number-field-action="increment" class="rui-number-field__stepper">+</button>
  </div>
</rui-number-field>

BEM classes are presentation-only.

Range and step

The step base follows the HTML rules: min when there is one, otherwise the input's value attribute. A value off the grid, such as 10 with max 10, min 0 and step 3, is reported by the input's validity.stepMismatch and blocks native submission; stepUp() and the arrow keys stop on the grid, so 9 is the largest value there.

Theming

Number field surfaces map to semantic surface roles, never Tailwind palette steps:

PartCSS roles
Group (.rui-number-field__group)border, background, rounded-control
Input (.rui-number-field__input)on-background text
Steppers (.rui-number-field__steppers)border divider
Stepper (.rui-number-field__stepper)on-surface, surface hover, surface-container-low active
Focus / invalidfocus-ring / error

Geometry shares control tokens (--size-control-sm, --space-control-*, --radius-control, --text-control) with RuiInput and RuiButton so form rows align. Override at the theme layer, not in component CSS.

API

RuiNumberField is a custom element (<rui-number-field>). Standalone it renders the input in a group; compose the view helpers for stepper buttons.

Attributes

AttributeTypeDefaultDescription
min-valuenumber-InfinityThe input's min, and the step base.
max-valuenumberInfinityThe input's max.
stepnumber1The input's step.
disabledbooleanfalseDisables the input and the steppers.
read-onlybooleanfalseSets readonly on the input and disables the steppers.
labelstring''Accessible name when there is no visible RuiLabel.
namestring''Form field name on the input.
increment-aria-labelstringIncrementAccessible name for the increment stepper.
decrement-aria-labelstringDecrementAccessible name for the decrement stepper.

The value property is not an attribute: it reads the input's number, undefined while the input holds none, and writing it writes the input. Set value after the element is defined, or write it as the input's value attribute: a write before upgrade shadows the property and is lost, as for any member that is not a @prop. RuiNumberField takes a value prop for its default input.

Light-DOM contract

TargetRequiredHost writesAuthor owns
[data-number-field-input]yesid, name, min, max, step, disabled, readonlytype="number" and value; stamp data-rui-control on the input for field wiring.
[data-number-field-action="decrement"]nodisabled, aria-labeldecrement button
[data-number-field-action="increment"]nodisabled, aria-labelincrement button
[data-number-field-group]nononepresentation wrapper only

Nested hosts: none.

Events

The input's own input and change bubble through the host, and host.value reads the input, so any listener reads the new number; the events carry no detail. Each stepper step dispatches both on the input after it moves the value, so holding a stepper sends a pair per step. A programmatic write to value dispatches nothing.

View helpers

ComponentTarget stampedNotes
RuiNumberFielddefault group when children omittedThe input alone, holding value; add RuiNumberFieldSteppers for buttons.
RuiNumberFieldGroup[data-number-field-group]Presentation only; not queried.
RuiNumberFieldInput[data-number-field-input]Always stamps data-rui-control.
RuiNumberFieldIncrementButton[data-number-field-action="increment"]Default label "Increment".
RuiNumberFieldDecrementButton[data-number-field-action="decrement"]Default label "Decrement".
RuiNumberFieldSteppersstepper column wrapperPresentation only.

CSS classes

Public BEM classes (documented via @cssclass):

ClassDescription
.rui-number-fieldRoot field wrapper.
.rui-number-field__groupControl-height bordered row.
.rui-number-field__inputBorderless input.
.rui-number-field__steppersTrailing stepper column.
.rui-number-field__stepperIcon button cell (+ / −).

Theme roles

PartCSS variables consumed
Group--border, --background, --radius-control, --duration-normal
Input--on-background, --space-control-x, --space-control-y, --text-control
Steppers--size-control-sm
Stepper states--on-surface, --surface, --surface-container-low
Focus / invalid--focus-ring / --error

Accessibility

  • The native number input is a spin button; the browser announces its value, range and step.
  • Stepper buttons need accessible names; "Increment" and "Decrement" are provided by default.
  • Announce min and max constraints in helper text when the valid range is not obvious.
  • Disabled fields should explain why editing is unavailable.