Forms

Number Field

A numeric field with steppers, range and step.

Rust
1use herogpui::components::number_field::{NumberField, NumberState};

Usage

Rust
1use herogpui::prelude::{NumberField, NumberState};
2
3NumberField::new(self.demo_number(
4    "nf-usage",
5    1024.,
6    0.,
7    4096.,
8    1.,
9    cx,
10))
11// v3's basic example seeds the field with `defaultValue`.
12.default_value(1024.)
13.min_value(0.)
14.name("width")
15.full_width(true)
16.label("Width")

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

NumberField

Number Field is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Number Field uses.

Styling

Number Field styling
StyleDescription
flex_col + gap(px(4.))Root field stack and four-pixel label/message spacing.
FIELD_HEIGHT + 40px buttons + apply_field_chromeThe default flex anatomy matches the three column geometry and shared field shell, with explicit 14px/20px group text; GPUI has no CSS grid or autofill pseudo-state.
apply_field_chromeState colors and focus shadow swap on a frame rather than interpolating.
Input::in_group + FIELD_TEXTInset, transparent grouped chrome and desktop text size match; GPUI text does not expose tabular numeral selection.
stepper_btn 40x36 + FIELD_ICONDefault cell and icon metrics match with a 15% placeholder seam.
stepper hover/press colorsButton color changes are immediate.
pressed_with_background(PRESSED_SCALE) + repeat taskFill, geometric scale and hold behavior match; arbitrary icon children keep their fixed dimensions and the transform ramp is immediate.
FieldVariant::Secondary + apply_field_chromeLower-emphasis field tokens are selected through FieldVariant.
full_width(true) + w_fullRoot and group both fill the available width.
vertical_steppers(true) + 24x18 cellsThe documented custom-class composition is available as a typed layout seam while preserving spin behavior.

API reference

Builders

Number Field builders
BuilderTypeDefaultDescription
content(render)AnyElement | Fn(values: NumberFieldRenderProps) -> AnyElementBuilt-in field anatomy or replacement content receiving the complete resolved number-field state.
full_width(bool)boolfalseExpands both the root and number group to the available width.
new(state)stateThe bound NumberState entity supplies stable GPUI identity rather than a element id.
variant(FieldVariant)FieldVariantFieldVariant::PrimarySelects elevated or lower-emphasis field chrome.
default_value(value)numberSeeds the uncontrolled NumberState once before render content observes it.
on_change(callback)Fn(value: number | undefined) -> ()Reports each changed numeric value; the local state cannot represent undefined empty value.
format_options(NumberFormat)NumberFormatSupports decimal, currency and percentage formatting without the complete Intl option surface.
is_required(bool)boolfalseMarks the label and live FormField required and blocks invalid native submission.
is_invalid(bool)boolfalseForces invalid chrome and validation reporting.
validate(callback)Fn(value: number) -> ValidationError | true | null | undefinedCustom validation returns one optional GPUI message.
validation_behavior(ValidationBehavior)ValidationBehaviorValidationBehavior::NativeChooses blocking native or non-blocking allow behavior.
validation_errors(errors)errorsServer messages take precedence over the custom validator.
min_value(value)numberInclusive lower bound for typing, keys, wheel input and steppers.
max_value(value)numberInclusive upper bound for typing, keys, wheel input and steppers.
step(value)number1Positive finite increment lattice shared by every input path.
is_disabled(bool)boolfalseDims the whole field, removes interaction and omits form data.
is_read_only(bool)boolfalseKeeps the field focusable while blocking text, key, wheel and stepper edits.
name(value)stringRegisters the current number under this form field name.
auto_focus(bool)boolfalseFocuses the numeric input once, including when replacement content is rendered.
vertical_steppers(bool)boolBuilds the group monolithically, including either horizontal buttons or the documented vertical-chevron composition.
increment_icon(icon)icon<IconPlus />Replaces the increment glyph while preserving the button's spin behavior.
decrement_icon(icon)icon<IconMinus />Replaces the decrement glyph while preserving the button's spin behavior.

Parts

Number Field parts
PartDescription
NumberFieldRoot stack owning numeric state, validation, formatting, focus and form registration.
NumberFieldUnified 36px field shell; composition is selected through typed builders rather than arbitrary children.
NumberFieldInner Input bound to NumberState and stripped of independent group-edge chrome.
NumberFieldBuilt-in repeatable spin button with caller-replaceable content.
NumberFieldRequired- and invalid-aware field label above the group.
NumberFieldHelp text shown below the group while the field is valid.
NumberFieldResolved server, custom or controlled validation message replacing Description.

States

Number Field states
BuilderStateDescription
validation::resolve + apply_field_chromeInvalidInvalid chrome and FieldError replace the normal description.
is_disabled + disabled_opacityDisabledThe whole field is dimmed, inert, omitted from form data and outside the tab order.
is_read_only interaction gatesRead onlyFocus remains available while every numeric mutation path is disabled.
shared Input focus_handle + apply_field_chromeFocus withinFocus on the input or either spin button uses the unified field focus treatment.
focus_visible + NumberFieldRenderStateFocus visibleReplacement content receives keyboard-visible focus state; the built-in group uses focus-within chrome.
group.hover(field/default hover)HoveredThe enabled unfocused group uses the hover fill and border; button hover intentionally has no additional rule body. Color interpolation is absent.
pressed_with_background + repeat taskPressedPress fills and geometrically scales the spin button while starting the repeat schedule; arbitrary icon children retain their own fixed size.
is_required + NumberFieldRenderStateRequiredRequired state reaches label, validation, form submission and replacement content.