-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
SpinButton: Add onChange handler #5326
Comments
The documentation makes this even more confusing, as it states for the
Unfortunately, the mentioned |
@JllyGrnGiant Thanks for reporting this, and sorry we didn't get to it sooner. And thanks @lafe for reporting the documentation issue. The similar current props are I think all three of those should be deprecated and replaced with the standard onChange?: (event: React.SyntheticEvent<HTMLElement>, newValue: string) => void; @kkjeer Since you've worked on other issues related to |
@ecraig12345 sorry for the delayed response. I think the proposed onChange signature looks fine, although it could probably be made more specific by using I also think it makes sense to deprecate |
Looked at this some more and I don't see an easy way to combine |
I suppose the request a Currently, I am almost duplicating all logic in <SpinButton
{...this.props}
componentRef={setRef}
onBlur={(ev) => this._onChange(Math.min(minValue, Math.max(maxValue, +ev.target.value)))}
onIncrement={(value) => this._onChange(Math.min(maxValue, +value + 1))}
onDecrement={(value) => this._onChange(Math.max(minValue, +value - 1))}
/> |
I try to fix this issue and found some issue. We need to answer some design questions before coding:
@ecraig12345 Do you have more context about this |
Hello, happy new year! I am going to continue working on this issue. The idea is to pass a How do you think about this solution? |
I'd defer to @jspurlin about the interface design, but it sounds fine to me. |
@lijunle what about if the user presses ENTER? Also, what about if the user is typing and then starts spinning the spin button (especially if why they are typing is garbage)? For the increment/decrement would you want to fire onChange on click, should it fire any time it spins (e.g. if someone mouseDowns on one of the buttons)? Also, what about spinning via the keybaord? You could imagine a case where a user types a value, starts spinning with the keyboard and then starts spinning via mouse; the "submit" behavior would be inconsistent when spinning via keybaord vs mouse. It doesn't sound like you are creating an onChange handler because that would fire on any change. It seems like you are wanting to know is some variation of setting a newValue (from validate) or when stop() is called for spinning. Potentially something like onValidValueUpdated. For example, you wouldn't want it to tell you the value was updated it was invalid and reverted to the original value |
It will trigger the
When start to spin button, the input box blur events happens and trigger the
Yes. The usage of this callback is to
The name |
@jspurlin @micahgodbolt @ecraig12345 I implemented the first version of the callback in #7577 . A new example is added. Could you please help to review it? I could like to write some unit test for it. What spec should we want? Here is my thoughts:
|
We plan to implement this in version 8--very sorry for the delay!! |
Finally coming back to this--I made a detailed spec based on this discussion which we'll be implementing in version 8. https://hackmd.io/cLn40UjfT_KOM6r4yi2CUQ Here's a dump of the spec as it was originally written (in case it's helpful for reference later if the hackmd goes away). I included a condensed and updated version in the PR. Intermediate vs. committed valuesSpinButton can have two types of values: intermediate and committed. A value is intermediate at any of the following times:
The value is committed when any of the following happens:
The commit phase consists of these steps:
Determining and storing the displayed valueWhere is the value stored?
What is the initial value? (in order of precedence)
What is the currently displayed value?
What is the value of
Edge cases:
When is
|
Describe the feature that you would like added
Make SpinButton useful by adding an OnChange handler.
As it is right now you have to figure out some way to accomplish the same effect using a combination of onIncrement, onDecrement, and onValidate which is really frustrating because it makes useful features of the control, like setting max and min values, unavailable since you have to manage the control yourself.
What component or utility would this be added to
SpinButton
Additional context/screenshots
Right now our team is trying to use a work-around of using TextField set with
type="number"
, but this doesn't include the nice accessibility aria attribute handling of SpinButton and is missing the useful max/min value clamping.I noticed the private _onChange method in the component has a comment saying there was a bug in React preventing onChange from being implemented. I assume that issue is no longer a blocker given that the issue is marked as closed and TextField has an onChange handler.
This affects VSTS.
Thanks!
The text was updated successfully, but these errors were encountered: