This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 143
Fix number inputs for IE11 #730
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
06ab12e
Manually convert values to numbers.
79142f9
Update CHANGELOG.
cb9f69b
Save parseInt and parseFloat values.
096f013
Use unary plus to convert to number.
1afbe7e
Merge branch 'dev' into ie11-numeric-input
Marc-Andre-Rivet 24b3b9d
Directly return result of convert.
21281de
Remove unnecessary wrapper function.
d6b7230
Update CHANGELOG.md
2016eba
Merge branch 'dev' into ie11-numeric-input
Marc-Andre-Rivet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,12 @@ export default class Input extends PureComponent { | |
this.onKeyPress = this.onKeyPress.bind(this); | ||
this.setInputValue = this.setInputValue.bind(this); | ||
this.setPropValue = this.setPropValue.bind(this); | ||
this.getValueAsNumber = this.getValueAsNumber.bind(this); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
const {value, valueAsNumber} = this.input.current; | ||
const {value} = this.input.current; | ||
const valueAsNumber = this.getValueAsNumber(value); | ||
this.setInputValue( | ||
isNil(valueAsNumber) ? value : valueAsNumber, | ||
nextProps.value | ||
|
@@ -42,7 +44,8 @@ export default class Input extends PureComponent { | |
} | ||
|
||
componentDidMount() { | ||
const {value, valueAsNumber} = this.input.current; | ||
const {value} = this.input.current; | ||
const valueAsNumber = this.getValueAsNumber(value); | ||
this.setInputValue( | ||
isNil(valueAsNumber) ? value : valueAsNumber, | ||
this.props.value | ||
|
@@ -89,6 +92,11 @@ export default class Input extends PureComponent { | |
); | ||
} | ||
|
||
getValueAsNumber(value) { | ||
const numericValue = convert(value); | ||
return numericValue % 1 === 0 ? Math.floor(numericValue) : numericValue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shammamah Can you explain the reasoning for this line? If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure if it would automatically convert to int vs. remaining as a float. Fixed in 24b3b9d. |
||
} | ||
|
||
setInputValue(base, value) { | ||
const __value = value; | ||
base = this.input.current.checkValidity() ? convert(base) : NaN; | ||
|
@@ -109,7 +117,8 @@ export default class Input extends PureComponent { | |
} | ||
|
||
onEvent() { | ||
const {value, valueAsNumber} = this.input.current; | ||
const {value} = this.input.current; | ||
const valueAsNumber = this.getValueAsNumber(value); | ||
if (this.props.type === 'number') { | ||
this.setPropValue( | ||
this.props.value, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.