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

feat(carousel): allow control mouse event #2436

Closed
wants to merge 4 commits into from

Conversation

DheerajVislavath
Copy link
Contributor

@DheerajVislavath DheerajVislavath commented Jun 5, 2018

This commit resolves issue #1163 , which allows the user to enable or disable the mouse events. Please review the pull requests and let me know if everything is good to be merged into. Thanks

Allows the user to Enable or disable the mouse event that controls the movement of carousel

fix ng-bootstrap#1163 ng-bootstrap#2422
@DheerajVislavath
Copy link
Contributor Author

Please review code and merge the changes. This will be an important feature.

Copy link
Member

@benouat benouat left a comment

Choose a reason for hiding this comment

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

@DheerajVislavath Thank you for your contribution!

Looking at the code to try to understand the feature, I think it should be named and handled differently.

Internally you can already pause the carrousel by specifying an interval of 0. So whenever you (mouseenter) I would save the interval value, set it to 0, and restore the saved value on (mouseleave)

Regarding the name, I would suggest @Input() pauseOnHover: boolean, with a default value of false.
Same for config.

Hope the explanations are clear so you could update the PR.

@DheerajVislavath
Copy link
Contributor Author

DheerajVislavath commented Jun 8, 2018

@benouat Thank you for your suggestions.
But , Carousel already has pause() and cycle() methods to set the interval values to 0 or given default interval. Why not make use of those methods ?

@benouat
Copy link
Member

benouat commented Jun 11, 2018

Carousel already has pause() and cycle() methods to set the interval values to 0 or given default interval. Why not make use of those methods ?

You're right !! I did not see these ones.

Then it should be even easier. You just need to introduce the pauseOnHover as an input & config

Allows the user to Enable or disable the mouse event that controls the movement of carousel
fix ng-bootstrap#1163 ng-bootstrap#2422
@DheerajVislavath
Copy link
Contributor Author

DheerajVislavath commented Jun 11, 2018

@benouat I implemented your suggested change. Please review and process to merge the code changes.
Thank you.

Copy link
Member

@benouat benouat left a comment

Choose a reason for hiding this comment

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

We are almost good @DheerajVislavath !

Would you mind addressing the few comments I left.

Also please make sure to rebase your branch to be fast forward.

it('should pause / resume slide change with time passage on mouse enter / leave', fakeAsync(() => {
const html = `
<ngb-carousel>
<ngb-carousel [pauseOnHover]='pauseOnHover'>
Copy link
Member

Choose a reason for hiding this comment

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

I don't see the point about adding that here. It basically duplicate with your added test.
Both 'should listen to mouse events based on pauseOnHover attribute' and 'should pause / resume slide change with time passage on mouse enter / leave' are the same.

@@ -39,8 +39,8 @@ export class NgbSlide {
'class': 'carousel slide',
'[style.display]': '"block"',
'tabIndex': '0',
'(mouseenter)': 'pause()',
'(mouseleave)': 'cycle()',
'(mouseenter)': 'mouseEventPause()',
Copy link
Member

Choose a reason for hiding this comment

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

I would rename it to onMouseEnter() as for now it won't be related to pause all the time.

'(mouseenter)': 'pause()',
'(mouseleave)': 'cycle()',
'(mouseenter)': 'mouseEventPause()',
'(mouseleave)': 'mouseEventCycle()',
Copy link
Member

Choose a reason for hiding this comment

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

I would rename it to onMouseLeave()

@@ -84,6 +84,11 @@ export class NgbCarousel implements AfterContentChecked,
*/
@Input() keyboard: boolean;

/**
* A flag to enable or disable mouse events
Copy link
Member

Choose a reason for hiding this comment

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

mouse events is too generic in here. we only check for mouse enter/leave

I would rephrase it to Flag to enable pause/resume on mouseover.

@pkozlowski-opensource
Copy link
Member

I did changes requested by @benouat, squashed and merged as 8d54cac.

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

3 participants