Skip to content
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/DP-12921: Prevents min/max from being past on InputNumber and InputCurrency. #503

Merged
merged 27 commits into from
Mar 20, 2019

Conversation

smurrayatwork
Copy link
Contributor

@smurrayatwork smurrayatwork commented Mar 11, 2019

Description

  • This changes InputNumber and InputCurrency so that changes made can't go beyond the passed in min/max values.
  • This also adds the npm package "is" to the repo. We should use this going forward for type checking.
  • Focusing InputCurrency will now remove the placeholder text if the input has no value, and place it back on blur if there is still no value.
  • Finally, InputCurrency has been changed so that focusing no longer switches the currency formatting to numbers.

Related Issue / Ticket

Steps to Test

  1. Pull the branch, npm install, run storybook, and browse to atoms -> forms -> Input(Number or Currency). Ensure that either input can no longer go beyond their set min or max values.

@clairesunstudio
Copy link
Contributor

clairesunstudio commented Mar 12, 2019

Since min/max only limits the inputs based on submission, and we are submitting values using onBlur. I think we should do a check in onBlur so that it's preventing out-of-bound values, both in inputCurrency and inputNumber.

I would suggest in handleChange/handleBlur we do a check and if input exceeds max, value will be set to max and if it exceeds min, it will be set to min. Let me know if that doesn't make sense.

@clairesunstudio
Copy link
Contributor

clairesunstudio commented Mar 12, 2019

If the value onChange is updated to a value exceeding the limits. the up/down keys and buttons stop work, because the check of newValue against min/max
inputCurrency
This could be fixed if we do what i mentioned above to prevent value to be out of bound

@clairesunstudio
Copy link
Contributor

clairesunstudio commented Mar 12, 2019

For InputCurrency formatting, is there a way to keep track on the actual number value with user interaction and have the display be a layer on top of that.

e.g. when user backspace it will remove digits and will prevent the displayed $ and , to be removed.

User should not be able to modify the displayed $ , .
inputCurrency-format

See these examples:
https://codepen.io/tutsplus/pen/PzpoWK
http://uipatterns.io/currency-input

@clairesunstudio
Copy link
Contributor

Changes work well except for InputNumber min is not setting to min onBlur:

Screen Shot 2019-03-15 at 9 44 14 AM

Screen Shot 2019-03-15 at 9 44 21 AM

@@ -14,8 +14,16 @@ storiesOf('atoms/forms', module)
'InputNumber', (() => {
const inputTextOptionsWithKnobs = Object.assign(...Object.entries(InputNumberOptions).map(([k, v]) => (
{ [k]: v() })));
const storyProps = {
style: (inputTextOptionsWithKnobs.inline) ? { width: '400px' } : { width: '200px' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only for testing purposes? do you want to you remove it to fix the visual regression?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for the story, but I should update the backstop image.

@clairesunstudio
Copy link
Contributor

clairesunstudio commented Mar 15, 2019

The other thing is in Form:
For some reason when input0 is set to 100 (max is 100) input1 becomes 90 instead of 0
form

Also onBlur only updates its own value doesn't rerender the other linked input, not sure if this is going to be an issue in the calculaters. i will npm link and test it out

const displayErrorMessage = (val, min, max, isRequired) => {
if (isRequired && String(val).length === 0) {
const displayErrorMessage = (val) => {
const { min, max, isRequired } = props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { min, max, isRequired } = props;
const { min, max, required } = props;

if (isRequired && String(val).length === 0) {
const displayErrorMessage = (val) => {
const { min, max, isRequired } = props;
if (isRequired && is.empty(val)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isRequired && is.empty(val)) {
if (required && is.empty(val)) {

});
}
},
onFocus: (e) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this unformatting logic back in this pr?

Changed
- (React) [InputNumber] DP-12921: Limits the component from changing value between the min and max passed.
- (React) [InputCurrency] DP-12921: Limits the component from changing value between the min and max passed.
- (React) [InputCurrency] DP-12734: Prevents changing currency to numbers from strings on focus.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update the changelog here - removing this per comment below.

@avrilpearl avrilpearl merged commit 0dd4371 into develop Mar 20, 2019
@avrilpearl avrilpearl deleted the react/DP-12921--input-min-max branch March 20, 2019 14:25
@clairesunstudio clairesunstudio mentioned this pull request Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants