For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/v/0.6.0/en/components/input-number.md.
  • English
  • InputNumber

    Enter numeric values such as quantities or prices.

    Basic usage

    Current quantity: 3
    basic.tsx
    import { Form, FormField, InputNumber, Text } from '@ifhover/leaf-ui';
    
    import { useState } from 'react';
    
    export function InputNumberBasic() {
      const [value, setValue] = useState<number | null>(3);
      return (
        <Form layout="vertical">
          <FormField label="Quantity">
            <InputNumber name="quantity" min={0} max={20} value={value} onChange={setValue} />
          </FormField>
          <FormField label="Price">
            <InputNumber min={0} step={0.1} precision={2} defaultValue={19.9} prefix="¥" />
          </FormField>
          <FormField label="Percentage">
            <InputNumber defaultValue={50} min={0} max={100} suffix="%" controls={false} />
          </FormField>
          <FormField label="Read only">
            <InputNumber defaultValue={12} readOnly />
          </FormField>
          <FormField label="Disabled">
            <InputNumber defaultValue={8} disabled />
          </FormField>
          <Text tone="muted">Current quantity: {value ?? 'Empty'}</Text>
        </Form>
      );
    }
    

    Formatting and exact decimals

    capabilities.tsx
    import { Form, FormField, InputNumber } from '@ifhover/leaf-ui';
    
    export function Capabilities() {
      return (
        <Form layout="vertical">
          <FormField label={'Grouped amount'}>
            <InputNumber defaultValue={12345.67} precision={2} grouping prefix="$" />
          </FormField>
          <FormField label={'Exact decimal string'}>
            <InputNumber
              stringMode
              name="amount"
              defaultValue="9007199254740993.01"
              step="0.01"
              precision={2}
            />
          </FormField>
          <FormField label={'Custom percent format'}>
            <InputNumber
              defaultValue={15}
              min={0}
              max={100}
              formatter={(value) => (value == null ? '' : `${value}%`)}
              parser={(text) => text.replace('%', '')}
            />
          </FormField>
        </Form>
      );
    }
    

    InputNumber API

    PropertyTypeDefaultDescription
    valuenumber | null | string | nullnullControlled / initial value; null is empty
    defaultValuenumber | null | string | nullnullControlled / initial value; null is empty
    onChange((value: number | null) => void) | ((value: string | null) => void)—Called for a valid number or clearing
    minnumber | stringUnboundedAllowed number range
    maxnumber | stringUnboundedAllowed number range
    stepnumber | string1Increment and decrement step
    precisionnumber—Decimal precision, from 0 to 15
    controlsbooleantrueShow increment and decrement buttons
    keyboardbooleantrueSupport arrow key increments
    size'sm' | 'md' | 'lg''md'Control size
    status'error' | 'warning'—Validation status
    prefixReactNode—Leading / trailing decoration
    suffixReactNode—Leading / trailing decoration
    stringModefalse | true—Use strings for exact values, steps and bounds.
    formatter( value: number | string | null, info: { userTyping: boolean; input: string }, ) => string—Format displayed text without changing the canonical form value.
    parser(text: string) => number | string—Parse displayed text back into a value.
    groupingboolean—Use localized digit grouping.
    localestring—Locale for language or numeric formatting.
    disabledbooleanfalseDisable interaction.
    readOnlybooleanfalseLock the value against typing, selection, clearing and removal.
    refRef<HTMLInputElement>—Input element ref

    Types

    Import the component props and item types when preparing your own values.

    import type { InputNumberProps } from '@ifhover/leaf-ui';

    Usage notes

    Partial minus signs and decimal points are preserved during typing. Blur or Enter normalizes the range and precision; stepping avoids common decimal accumulation errors. Use name for FormData submission. required, form and autoComplete reach the input, and form reset is supported. className and style apply to the wrapper.

    NumericInputNumber API

    PropertyTypeDefaultDescription
    valuenumber | null—Controlled value.
    defaultValuenumber | nullnullInitial value; uncontrolled fields support native form reset.
    onChange(value: number | null) => void—Called when the value changes.
    minnumber—Minimum allowed value.
    maxnumber—Maximum allowed value.
    stepnumber1Step; Slider uses only marked values when null.
    precisionnumber—Decimal precision.
    controlsbooleantrueConfigure controls.
    keyboardbooleantrueConfigure keyboard.
    size'sm' | 'md' | 'lg''md'Presentation size.
    status'error' | 'warning'—Configure status.
    prefixReactNode—Leading content.
    suffixReactNode—Trailing content.
    stringModefalse—Use strings for exact values, steps and bounds.
    formatter( value: number | string | null, info: { userTyping: boolean; input: string }, ) => string—Format displayed text without changing the canonical form value.
    parser(text: string) => number | string—Parse displayed text back into a value.
    groupingboolean—Use localized digit grouping.
    localestring—Locale for language or numeric formatting.

    StringInputNumber API

    PropertyTypeDefaultDescription
    precisionnumber—Decimal precision.
    controlsbooleantrueConfigure controls.
    keyboardbooleantrueConfigure keyboard.
    size'sm' | 'md' | 'lg''md'Presentation size.
    status'error' | 'warning'—Configure status.
    prefixReactNode—Leading content.
    suffixReactNode—Trailing content.
    formatter( value: number | string | null, info: { userTyping: boolean; input: string }, ) => string—Format displayed text without changing the canonical form value.
    parser(text: string) => number | string—Parse displayed text back into a value.
    groupingboolean—Use localized digit grouping.
    localestring—Locale for language or numeric formatting.
    stringModetrue—Required. Use strings for exact values, steps and bounds.
    valuestring | null—Controlled value.
    defaultValuestring | nullnullInitial value; uncontrolled fields support native form reset.
    onChange(value: string | null) => void—Called when the value changes.
    minstring—Minimum allowed value.
    maxstring—Maximum allowed value.
    stepstring'1'Step; Slider uses only marked values when null.