InputNumber
Enter a number within certain range with the mouse or keyboard.
When To Use#
When a numeric value needs to be provided.
Examples
import { InputNumber } from 'antd';
function onChange(value) {
console.log('changed', value);
}
ReactDOM.render(
<InputNumber min={1} max={10} defaultValue={3} onChange={onChange} />
, mountNode);
import { InputNumber, Button } from 'antd';
class App extends React.Component {
state = {
disabled: true,
};
toggle = () => {
this.setState({
disabled: !this.state.disabled,
});
}
render() {
return (
<div>
<InputNumber min={1} max={10} disabled={this.state.disabled} defaultValue={3} />
<div style={{ marginTop: 20 }}>
<Button onClick={this.toggle} type="primary">Toggle disabled</Button>
</div>
</div>
);
}
}
ReactDOM.render(<App />, mountNode);
import { InputNumber } from 'antd';
function onChange(value) {
console.log('changed', value);
}
ReactDOM.render(
<div>
<InputNumber
defaultValue={1000}
formatter={value => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
parser={value => value.replace(/\$\s?|(,*)/g, '')}
onChange={onChange}
/>
<InputNumber
defaultValue={100}
min={0}
max={100}
formatter={value => `${value}%`}
parser={value => value.replace('%', '')}
onChange={onChange}
/>
</div>
, mountNode);
import { InputNumber } from 'antd';
function onChange(value) {
console.log('changed', value);
}
ReactDOM.render(
<div>
<InputNumber size="large" min={1} max={100000} defaultValue={3} onChange={onChange} />
<InputNumber min={1} max={100000} defaultValue={3} onChange={onChange} />
<InputNumber size="small" min={1} max={100000} defaultValue={3} onChange={onChange} />
</div>
, mountNode);
.ant-input-number {
margin-right: 10px;
}
import { InputNumber } from 'antd';
function onChange(value) {
console.log('changed', value);
}
ReactDOM.render(
<InputNumber min={0} max={10} step={0.1} onChange={onChange} />
, mountNode);
API#
property | description | type | default |
---|---|---|---|
min | min value | number | -Infinity |
max | max vale | number | Infinity |
value | current value | number | |
step | The number to which the current value is increased or decreased. It can be an integer or decimal. | number|string | 1 |
precision | precision of input value | number | - |
defaultValue | initial value | number | |
onChange | The callback triggered when the value is changed. | function(value: number | string) | |
disabled | disable the input | boolean | false |
size | width of input box | string | - |
formatter | Specifies the format of the value presented | function(value: number | string): string | - |
parser | Specifies the value extracted from formatter | function( string): number | - |