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

fix: respect max and min in NumberInput when using arrows #4563

Merged
merged 7 commits into from
Dec 5, 2019

Conversation

rudolpho1
Copy link
Contributor

The arrow keys in the NumberInput allow users to step below the min and above the max value. This issue is fixed here.

Changelog

Changed

  • Change the NumberInput to respect min and max values when using arrow keys

Testing / Reviewing

In order to reproduce the issue do the following:

  • Create a NumberInput with min 0, max 100 and step 10

  • manually enter the value 5 into the NumberInput

  • click the arrow down.

actual behavior: the value of the NumberInput changes to -5

expected behavior: the value of the NumberInput changes to 0

@rudolpho1 rudolpho1 requested a review from a team as a code owner November 5, 2019 14:56
@ghost ghost requested review from emyarod and joshblack November 5, 2019 14:57
@netlify
Copy link

netlify bot commented Nov 5, 2019

Deploy preview for the-carbon-components ready!

Built with commit 10d37cf

https://deploy-preview-4563--the-carbon-components.netlify.com

@netlify
Copy link

netlify bot commented Nov 5, 2019

Deploy preview for carbon-elements ready!

Built with commit 10d37cf

https://deploy-preview-4563--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Nov 5, 2019

Deploy preview for carbon-components-react ready!

Built with commit 10d37cf

https://deploy-preview-4563--carbon-components-react.netlify.com

@netlify
Copy link

netlify bot commented Nov 5, 2019

Deploy preview for carbon-components-react failed.

Built with commit f0e41c5

https://app.netlify.com/sites/carbon-components-react/deploys/5de9795759fad60009964190

@netlify
Copy link

netlify bot commented Nov 5, 2019

Deploy preview for carbon-elements ready!

Built with commit f0e41c5

https://deploy-preview-4563--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Nov 5, 2019

Deploy preview for the-carbon-components ready!

Built with commit f0e41c5

https://deploy-preview-4563--the-carbon-components.netlify.com

@abbeyhrt
Copy link
Contributor

abbeyhrt commented Nov 5, 2019

Hi @rudolpho1! Thank you for taking the time to contribute. We are already addressing the issue with min/max not being respected as a part of an overhaul of NumberInput, here's the related issue: #2477, and we're taking a different approach UX-wise to address this problem. In the future, before creating a PR, could you open an issue with the problem you ran into? It would be really helpful for us so we can confirm the problem and make sure that no duplicate work is being done 👍

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

Hi 👋 thank you for jumping in! Could you please fix the logic at

? (min !== undefined && value > min) || min === undefined
: (max !== undefined && value < max) || max === undefined;
rather than adding logic? Specifically, we need to ensure that the event handler won't run if the value shouldn't be changed.

@abbeyhrt
Copy link
Contributor

abbeyhrt commented Nov 6, 2019

@rudolpho1 you can ignore my previous comment! I interpreted the arrows as the arrow keys, not the increment and decrement buttons.

@rudolpho1
Copy link
Contributor Author

@asudoh changing the conditional instead of the logic would mean that if the current value is 5 and you hit the decrement button the value would still be 5. But my expectation would be that it changes to the lowest possible value i.e. 0. With my logic, it is correct that the change handler fires, because the value does in fact change. If the current value is already the min (or max) value, then the conditional would already be false and nothing would happen and no event would be fired. So, I think the behaviour is correct this way. What do you think?

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

OK makes sense - Thank you for your additional explanation @rudolpho1!

Copy link
Member

@emyarod emyarod left a comment

Choose a reason for hiding this comment

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

looks good to me, would you mind adding/refactoring the existing tests for these scenarios (trying to increment past max or decrement below min)?

@joshblack joshblack requested a review from a team as a code owner November 20, 2019 20:07
@ghost ghost requested a review from emyarod November 20, 2019 20:07
Copy link
Member

@emyarod emyarod left a comment

Choose a reason for hiding this comment

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

this looks good to me but I just requested some testing for core component features since this seems like a common scenario

@asudoh asudoh merged commit 2b22855 into carbon-design-system:master Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants