Skip to content

Commit

Permalink
Fix Duplicate Percentage in EdibleInput
Browse files Browse the repository at this point in the history
Fixes #628
  • Loading branch information
casesandberg committed May 3, 2020
1 parent cf25253 commit 2c8dfca
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/components/common/EditableInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const VALID_KEY_CODES = [
DOWN_KEY_CODE
]
const isValidKeyCode = keyCode => VALID_KEY_CODES.indexOf(keyCode) > -1

const getFormattedPercentage = number => `${number}%`
const getNumberValue = value => Number(String(value).replace(/%/g, ''))
const getIsPercentage = value => String(value).indexOf('%') > -1

export class EditableInput extends (PureComponent || Component) {
constructor(props) {
Expand Down Expand Up @@ -55,10 +52,8 @@ export class EditableInput extends (PureComponent || Component) {
}

handleChange = (e) => {
const value = getNumberValue(e.target.value)
if (!isNaN(value)) {
this.setUpdatedValue(value, e)
}
console.log(e.target.value)
this.setUpdatedValue(e.target.value, e)
}

getArrowOffset() {
Expand All @@ -82,10 +77,7 @@ export class EditableInput extends (PureComponent || Component) {
const onChangeValue = this.props.label ? this.getValueObjectWithLabel(value) : value
this.props.onChange && this.props.onChange(onChangeValue, e)

const isPercentage = getIsPercentage(e.target.value)
this.setState({
value: isPercentage ? getFormattedPercentage(value) : value
})
this.setState({ value })
}

handleDrag = (e) => {
Expand Down

0 comments on commit 2c8dfca

Please sign in to comment.