React Input Number Component

9.5.0 · renamed · verified Sun Apr 19

This package provides a foundational and unstyled React component for handling numeric input. It includes built-in increment and decrement controls, making it suitable for building custom number input experiences. The current stable version, under its new scope, is `@rc-component/input-number@1.6.2`. Historically, it was known as `rc-input-number` before being renamed to the scoped package in version 1.5.0. The project maintains an active release cadence, with frequent patch and minor updates, indicating ongoing development and improvements. Its primary differentiator is its low-level, highly customizable nature, providing core functionality without imposing specific UI/UX styles, which allows other UI libraries (like Ant Design) to build upon it, rather than being a full-featured, opinionated component itself.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic controlled `InputNumber` component with min/max, step, and change handling, highlighting its unstyled nature that requires custom CSS for presentation.

import React, { useState } from 'react';
import InputNumber from '@rc-component/input-number';

// Basic CSS for visibility (you would typically integrate with your design system)
const inputNumberStyles = {
  width: 120,
  padding: 8,
  borderRadius: 4,
  border: '1px solid #ccc',
  fontSize: 16
};

export default function MyInputNumber() {
  const [value, setValue] = useState(10);

  const onChange = (newValue: number | null) => {
    console.log('Value changed:', newValue);
    // The component can return null for empty input, handle as needed
    setValue(newValue === null ? 0 : newValue);
  };

  return (
    <div>
      <h3>Basic InputNumber Example</h3>
      <InputNumber
        min={0}
        max={100}
        step={1}
        defaultValue={10}
        value={value}
        onChange={onChange}
        placeholder="Enter a number"
        style={inputNumberStyles}
        // Use prefixCls for targeted CSS customization
        prefixCls="my-custom-input-number"
      />
      <p>Current Value: {value}</p>
      <button onClick={() => setValue(value + 5)}>Increment by 5</button>
      <p>This component is unstyled and requires custom CSS for visual appearance.</p>
    </div>
  );
}

view raw JSON →