From 7240008f0cacfe3a6880ddc0b0f02c25d5a7f089 Mon Sep 17 00:00:00 2001 From: Marco Cesarato Date: Fri, 25 Sep 2020 12:53:37 +0200 Subject: [PATCH] feat: add initial value prop --- PROPS.md | 1 + README.md | 3 ++- index.js | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/PROPS.md b/PROPS.md index 0ba7784..5922914 100644 --- a/PROPS.md +++ b/PROPS.md @@ -34,6 +34,7 @@ | `fontFamily` | Custom fontFamily of the text input of the Spinner | String | System Default | | | `fontSize` | Custom fontSize of the text input of the Spinner | Number | `14` | | | `height` | Custom height of the Spinner | Number | `50` | | +| `initialValue` | Initial value of the Spinner | String
Number | `0` | | | `inputStyle` | Input Style (Text number at middle) | Object | | Could overwrite other props | | `maxLength` | Limits the maximum number of characters that can be entered. | Number | | | | `max` | Max number permitted | String
Number | `0` | | diff --git a/README.md b/README.md index 6ecde5c..0d5e7d7 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,8 @@ Check the "[Props List](PROPS.md)" file to have the complete list of component p | `append` | Custom element before right button | Component | | | | `autofocus` | If `true`, focuses the input on `componentDidMount`. | | `false` | | | `disabled` | Disable the Spinner or not | Boolean | `false` | | -| `editable` | Set if input number field is editable or not | Boolean | `true` | | +| `editable` | Set if input number field is editable or not | Boolean | `true` | | +| `initialValue` | Initial value of the Spinner | String
Number | `0` | | | `maxLength` | Limits the maximum number of characters that can be entered. | Number | | | | `max` | Max number permitted | String
Number | `0` | | `min` | Min value permitted | String
Number | `99` | diff --git a/index.js b/index.js index 9394b6f..52c1e5e 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ class InputSpinner extends Component { this.state = { min: this.parseNum(this.props.min), max: this.parseNum(this.props.max), - value: this.parseNum(this.props.value), + value: this.parseNum(!isNaN(this.props.initialValue) ? this.props.initialValue : this.props.value), step: spinnerStep, focused: false, buttonPress: null, @@ -828,6 +828,7 @@ InputSpinner.defaultProps = { min: 0, max: 999, value: 0, + initialValue: null, step: 1, precision: 2, rounded: true,