-
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
add onChanged prop on Slider (#6108) #6127
Conversation
@@ -72,6 +72,11 @@ export interface ISliderProps extends React.Props<SliderBase> { | |||
*/ | |||
onChange?: (value: number) => void; | |||
|
|||
/** | |||
* Callback when the mouse is released |
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.
Mouse or touch, right?
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.
Yes indeed, I'll change the comment.
@@ -258,6 +258,10 @@ export class SliderBase extends BaseComponent<ISliderProps, ISliderState> implem | |||
renderedValue: this.state.value | |||
}); | |||
|
|||
if (this.props.onBlur) { |
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.
We've had a request to make a small change to the prop.
- onBlur should be reserved for the actual onBlur event on the button (mouse release is actually blurring)
- as we eventually need to change onChange to onChange(event, item) (A breaking change) lets be sure that our new prop uses this new, non deprecated interface
So lets go with onChanged (past tense) with an interface of (ev, value). This will take a few tweaks up in _onMouseDownOrTouchStart to pass the event through.
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.
Appreciate the changes @blandine, once these changes are in I'll get this merged and a build will kick off before the next business day.
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.
Thanks for the review, I'll change it today (hopefully!).
@@ -252,12 +252,16 @@ export class SliderBase extends BaseComponent<ISliderProps, ISliderState> implem | |||
); | |||
} | |||
|
|||
private _onMouseUpOrTouchEnd = (): void => { | |||
private _onMouseUpOrTouchEnd = (event: MouseEvent | TouchEvent): void => { |
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.
Does this work without modifying lines 167 and 170? Maybe i just don't know how that _events.on callback takes in props.
Last thing then, can you add a quick test to make sure this onChanged returns the event and correct number?
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 tried to add a test previously but I didn't succeed to simulate a mousedown and then a mouseup to trigger the onChanged.
I followed this issue enzymejs/enzyme#426 and this one : enzymejs/enzyme#1357 saying that we should not use Enzyme simulate anymore.
Could you give me some pointers?
Thanks
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.
For now, i'd just piggyback off of the existing onChange test and make sure your onChanged callback is being fired as well (including event). I agree, it seems enzyme is moving away from simulate, so no need to do anything elaborate.
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.
It can't work since onChanged is fired only when the mouseup or touchend happens.
On mousedown event (like in the extisting onChange test), onChanged won't be triggered.
I try to hack something like in the callout.test.tsx but it doesn't work :
const mouseEvent = document.createEvent('MouseEvent');
const root = document.createElement('div');
document.body.appendChild(root);
ReactDOM.render<HTMLDivElement>(<Slider onChanged={onChanged} />, root);
mouseEvent.initMouseEvent('mousedown', false, false, window, 0, 0, 0, 0, 0, false, false, false, false, 1, root);
mouseEvent.initMouseEvent('mouseup', false, false, window, 0, 0, 0, 0, 0, false, false, false, false, 1, root);
Thank you for your time but I'm afraid I won't be able to complete this PR :/
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.
Last change, just add a quick test, then this is good to go.
I don't want this to block your ability to contribute. Thanks for trying as hard as you could with the tests. |
Pull request checklist
$ npm run change
Description of changes
In Slider component, there is a new prop 'onBlur' which is called on mouseUp or touchEnd
Focus areas to test
I tried to add test in the .spec file but I don't know how to simulate the mouseUp event since it's a listener on the window object. I'm open to suggestions :)
Microsoft Reviewers: Open in CodeFlow