Socket
Socket
Sign inDemoInstall

rc-input-number

Package Overview
Dependencies
12
Maintainers
8
Versions
215
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc-input-number

React input-number component


Version published
Maintainers
8
Weekly downloads
1,222,337
increased by4.23%
Install size
729 kB

Weekly downloads

Package description

What is rc-input-number?

The rc-input-number package is a React component that provides an input field specifically designed for numeric values. It allows users to input numbers either by typing them directly or by using increment and decrement buttons. This package offers features such as precision control, keyboard navigation, and customizable styles.

What are rc-input-number's main functionalities?

Basic Numeric Input

This code sample demonstrates how to create a basic numeric input field with a default value, minimum, and maximum value.

import InputNumber from 'rc-input-number';

function App() {
  return (
    <InputNumber
      defaultValue={3}
      min={1}
      max={10}
    />
  );
}

Precision Control

This code sample shows how to set the step and precision for the numeric input, allowing users to increment or decrement by a specific value and control the number of digits after the decimal point.

import InputNumber from 'rc-input-number';

function App() {
  return (
    <InputNumber
      defaultValue={3.5}
      step={0.1}
      precision={2}
    />
  );
}

Keyboard Navigation

This code sample illustrates how to handle keyboard events, enabling users to navigate and modify the input value using their keyboard.

import InputNumber from 'rc-input-number';

function App() {
  return (
    <InputNumber
      defaultValue={3}
      onKeyDown={(e) => console.log('KeyDown', e)}
    />
  );
}

Custom Styles

This code sample demonstrates how to apply custom styles to the numeric input component to match the design requirements of your application.

import InputNumber from 'rc-input-number';

function App() {
  return (
    <InputNumber
      defaultValue={3}
      style={{ width: 100 }}
    />
  );
}

Other packages similar to rc-input-number

Readme

Source

rc-input-number

Input number control.

NPM version dumi build status Test coverage Dependencies DevDependencies npm download bundle size

Screenshots

Install

rc-input-number

Usage

import InputNumber from 'rc-input-number';

export default () => <InputNumber defaultValue={10} />;

Development

npm install
npm start

Example

http://127.0.0.1:8000/examples/

online example: https://input-number.vercel.app/

API

props

nametypedefaultdescription
prefixClsstringrc-input-numberSpecifies the class prefix
minNumberSpecifies the minimum value
onClick
placeholderstring
maxNumberSpecifies the maximum value
stepNumber or String1Specifies the legal number intervals
precisionNumberSpecifies the precision length of value
disabledBooleanfalseSpecifies that an InputNumber should be disabled
requiredBooleanfalseSpecifies that an InputNumber is required
autoFocusBooleanfalseSpecifies that an InputNumber should automatically get focus when the page loads
readOnlyBooleanfalseSpecifies that an InputNumber is read only
controlsBooleantrueWhether to enable the control buttons
nameStringSpecifies the name of an InputNumber
idStringSpecifies the id of an InputNumber
valueNumberSpecifies the value of an InputNumber
defaultValueNumberSpecifies the defaultValue of an InputNumber
onChangeFunctionCalled when value of an InputNumber changed
onBlurFunctionCalled when user leaves an input field
onPressEnterFunctionThe callback function that is triggered when Enter key is pressed.
onFocusFunctionCalled when an element gets focus
styleObjectroot style. such as {width:100}
upHandlerReact.Nodecustom the up step element
downHandlerReact.Nodecustom the down step element
formatter(value: number|string): displayValue: stringSpecifies the format of the value presented
parser(displayValue: string) => value: number`input => input.replace(/[^\w\.-]*/g, '')`Specifies the value extracted from formatter
patternstringSpecifies a regex pattern to be added to the input number element - useful for forcing iOS to open the number pad instead of the normal keyboard (supply a regex of "\d*" to do this) or form validation
decimalSeparatorstringSpecifies the decimal separator
inputModestringSpecifies the inputmode of input
wheelBooleantrueAllows changing value with mouse wheel

Keyboard Navigation

  • When you hit the or key, the input value will be increased or decreased by step
  • With the Shift key (Shift+⬆, Shift+⬇), the input value will be changed by 10 * step
  • With the Ctrl or key (Ctrl+⬆ or ⌘+⬆ or Ctrl+⬇ or ⌘+⬇ ), the input value will be changed by 0.1 * step

Mouse Wheel

  • When you scroll up or down, the input value will be increased or decreased by step
  • Scrolling with the Shift key, the input value will be changed by 10 * step

Test Case

npm test
npm run chrome-test

Coverage

npm run coverage

open coverage/ dir

License

rc-input-number is released under the MIT license.

Keywords

FAQs

Last updated on 26 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc