-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react/fix inputNumber handleAdjust logic #518
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clairesunstudio --> this looks good to me, obviously made a bunch of updates to the previous logic so feel free to merge it once you review those.
changes looks good to me one small thing i noticed that in InputCurrency, if you put in a dollar value becomes 0, vs if you put in any other invalid character value becomes "" |
const handleBlur = () => { | ||
const inputEl = ref.current; | ||
if (is.empty(inputEl.value)) { | ||
const stringValue = inputEl.value; | ||
const isNotNumber = !stringValue || isNaN(Number(numbro.unformat(stringValue))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const isNotNumber = !stringValue || isNaN(Number(numbro.unformat(stringValue))); | |
const isNotNumber = is.empty(stringValue) || Number.isNaN(Number(numbro.unformat(stringValue))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is doing the same thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because stringValue can't be number 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number.isNaN() is the same as isNaN() since we already made the parameter a number
newValue = props.min; | ||
} | ||
let newValue = inputEl.value ? Number(inputEl.value) : inputEl.value; | ||
if (hasNumberProperty(props, 'max') && newValue > props.max) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (hasNumberProperty(props, 'max') && newValue > props.max) { | |
if (hasNumberProperty(props, 'max') && (is.number(newValue) && newValue > props.max)) { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is not needed, you can only enter numbers, periods, commas, or null in an input type number
, so this will be a number null, or a string of .
or ,
which will evaluate to false above.
if (!is.empty(inputEl.value)) { | ||
inputEl.value = Number(numbro(newValue) | ||
.format({ mantissa: countDecimals(props.step) })); | ||
if (hasNumberProperty(props, 'min') && newValue < props.min) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (hasNumberProperty(props, 'min') && newValue < props.min) { | |
if (hasNumberProperty(props, 'min') && (is.number(newValue) && newValue < props.min)) { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is not needed, you can only enter numbers, periods, commas, or null in an input type number, so this will be a number null, or a string of . or , which will evaluate to false above.
} | ||
handleChange(e); | ||
let newValue = inputEl.value ? Number(inputEl.value) : inputEl.value; | ||
if (direction === 'up' && (!hasNumberProperty(props, 'max') || newValue < props.max)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (direction === 'up' && (!hasNumberProperty(props, 'max') || newValue < props.max)) { | |
if (direction === 'up' && (!hasNumberProperty(props, 'max') || (is.number(newValue) && newValue < props.max))) { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is not needed, you can only enter numbers, periods, commas, or null in an input type number, so this will be a number, null, or a string of . or , - null and strings will evaluate to false above which is correct so this is fine.
handleChange(e); | ||
let newValue = inputEl.value ? Number(inputEl.value) : inputEl.value; | ||
if (direction === 'up' && (!hasNumberProperty(props, 'max') || newValue < props.max)) { | ||
newValue = newValue ? (newValue + props.step).toFixed(countDecimals(props.step)) : props.step; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if newValue is a string, toFixed won't work because it doesn't exist.
newValue = newValue ? (newValue + props.step).toFixed(countDecimals(props.step)) : props.step; | |
newValue = newValue ? Number(newValue + props.step).toFixed(countDecimals(props.step)) : props.step; |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newvalue would already be a number at this point - we do not need to cast it again. --> newValue < props.max would only evaluate to true if is was a number less than min prop
props.onChange(e, newValue, props.id); | ||
} | ||
}); | ||
} else if (direction === 'down' && (!hasNumberProperty(props, 'min') || newValue > props.min)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (direction === 'down' && (!hasNumberProperty(props, 'min') || newValue > props.min)) { | |
} else if (direction === 'down' && (!hasNumberProperty(props, 'min') || (is.number(newValue) && newValue > props.min))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is not needed, you can only enter numbers, periods, commas, or null in an input type number, so this will be a number, null, or a string of . or , - null and strings will evaluate to false above which is correct so this is fine.
} | ||
}); | ||
} else if (direction === 'down' && (!hasNumberProperty(props, 'min') || newValue > props.min)) { | ||
newValue = newValue ? (newValue + props.step * -1).toFixed(countDecimals(props.step)) : (props.step * -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newValue = newValue ? (newValue + props.step * -1).toFixed(countDecimals(props.step)) : (props.step * -1); | |
newValue = newValue ? Number(newValue + props.step * -1).toFixed(countDecimals(props.step)) : (props.step * -1); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newvalue would already be a number at this point - we do not need to cast it again. --> newValue > props.min would only evaluate to true if is was a number greater than min prop
Co-Authored-By: clairesunstudio <[email protected]>
Fixed
To test: