# react-input-numeric

> Better number input for React

Latest version **1.0.1** (published 2018-07-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install react-input-numeric
pnpm add react-input-numeric
yarn add react-input-numeric
bun add react-input-numeric
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-07-14 |
| First published | 2018-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 36.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Samuel Meuli |
| Maintainers | samuelmeuli |
| Keywords | react, component, react-component, input, number, numeric, form |

## Links

- npm: https://www.npmjs.com/package/react-input-numeric
- Repository: https://github.com/samuelmeuli/react-input-numeric
- Homepage: https://samuelmeuli.github.io/react-input-numeric
- Issues: https://github.com/samuelmeuli/react-input-numeric/issues
- npm.io page: https://npm.io/package/react-input-numeric

## Dependencies (2)

- [decimal.js](https://npm.io/package/decimal.js.md) ^10.0.1
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-07-14
- 1.0.0 — 2018-05-16

## README

# react-input-numeric

[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/smeuli/react-input-numeric/blob/master/LICENSE)
[![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/smeuli/react-input-numeric/pulls)

**Better number input for React**

* Simple to configure
* Customizable
* Same look across browsers
* Touch screen friendly

→ **[Demo](https://samuelmeuli.github.io/react-input-numeric)**

<img src="demo.gif" alt="Demo" width="200">


## Usage

Install the package using NPM:

```
npm install react-input-numeric
```

Add the component to your React application:

```jsx
import InputNumeric from 'react-input-numeric';

// Somewhere in your code:
<InputNumeric
  value={this.state.value}
  onChange={value => this.setState({ value })}
/>
```


## Full example

```jsx
import React, { Component } from 'react';
import InputNumeric from 'react-input-numeric';

export default class ExampleComponent extends Component {
  constructor() {
    super();
    this.state = {
      value: 0
    };
  }

  render() {
    return (
      <InputNumeric
        value={this.state.value}
        onChange={value => this.setState({ value })}
      />
    );
  }
}
```


## Props

Prop | Type | Default | Description
---- | ---- | ------- | -----------
`value` (required) | Number | – | Value currently displayed in the input field
`max` | Number | – | Maximal value
`min` | Number | – | Minimal value
`decimals` | Number (integer) | `2` | Number of digits after the decimal point
`step` | Number | `1` | Difference between the possible values (e.g. `1` only allows integers)
`name` | String | – | HTML `name` attribute to be assigned to the input field
`disabled` | Boolean | `false` | Input should not be editable and buttons not clickable
`showButtons` | Boolean | `true` | Show/hide buttons for incrementing/decrementing
`showTrailingZeros` | Boolean | `false` | Display e.g. `4.00` instead of `4` (with `decimals={2}`)
`snapToStep` | Boolean | `false` | Snap manually entered values to the nearest multiple of `step`
`onBlur` | Function | – | Function to be executed when the component loses focus (current value is passed as parameter)
`onChange` | Function | – | Function to be executed when the value is changed (new value is passed as parameter)
`onFocus` | Function | – | Function to be executed when the input field gets focus (current value is passed as parameter)


## More information

* The value can also be incremented/decremented using the up/down arrow keys
* When setting the `decimals` prop, the exact value is always stored and passed to the `onBlur`, `onChange`, and `onFocus` functions. Only the value displayed to the user is rounded.
* The component uses [decimal.js](https://github.com/MikeMcl/decimal.js/) internally for handling arbitrary-precision decimals


## Development

* `git clone`
* `npm install`
* `npm start` to generate the library bundle using [Rollup](https://github.com/rollup/rollup)
* Open `localhost:3000` to see the component in action using [Storybook](https://github.com/storybooks/storybook)

---
_Source: https://npm.io/package/react-input-numeric · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
