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

add onChanged prop on Slider (#6108) #6127

Merged
merged 1 commit into from Sep 4, 2018
Merged

add onChanged prop on Slider (#6108) #6127

merged 1 commit into from Sep 4, 2018

Conversation

blandine
Copy link
Contributor

@blandine blandine commented Aug 29, 2018

Pull request checklist

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

@msftclas
Copy link

msftclas commented Aug 29, 2018

CLA assistant check
All CLA requirements met.

@@ -72,6 +72,11 @@ export interface ISliderProps extends React.Props<SliderBase> {
*/
onChange?: (value: number) => void;

/**
* Callback when the mouse is released
Copy link
Member

Choose a reason for hiding this comment

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

Mouse or touch, right?

Copy link
Contributor Author

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) {
Copy link
Member

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.

  1. onBlur should be reserved for the actual onBlur event on the button (mouse release is actually blurring)
  2. 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.

Copy link
Member

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.

Copy link
Contributor Author

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 => {
Copy link
Member

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?

Copy link
Contributor Author

@blandine blandine Aug 31, 2018

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

Copy link
Member

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.

Copy link
Contributor Author

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 :/

Copy link
Member

@micahgodbolt micahgodbolt left a 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.

@micahgodbolt
Copy link
Member

I don't want this to block your ability to contribute. Thanks for trying as hard as you could with the tests.

@micahgodbolt micahgodbolt merged commit 7b9f8ed into microsoft:master Sep 4, 2018
@micahgodbolt micahgodbolt changed the title add onBlur prop on Slider (#6108) add onChanged prop on Slider (#6108) Sep 11, 2018
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slider onChange event should be triggered when the mouse click has been released
3 participants