-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(carousel): stay paused after calling pause() until cycle() is ca…
…lled (#3225) After setting the carousel on pause through its `pause()` method and clicking on navigation arrows, the carousel no longer automatically restarts. Calling the `cycle()` method is needed to undo the effect of the `pause()` method. When `pauseOnHover` is true, hovering on the carousel no longer uses the `pause()` and `cycle()` methods. The hover status is stored separately, so that calling pause() and removing the mouse from the carousel no longer restarts it automatically. In order for the user to have more control, we also introduce: + The slide event now has a "source" property allowing to know what triggered the event: "timer", "arrowLeft", "arrowRight" or "indicator". + The "paused" boolean status is now also included in the slide event. Closes #3188
- Loading branch information
Showing
8 changed files
with
334 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
demo/src/app/components/carousel/demos/pause/carousel-pause.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<ngb-carousel #carousel interval="1000" [pauseOnHover]="pauseOnHover" (slide)="onSlide($event)"> | ||
<ng-template ngbSlide *ngFor="let img of images; index as i"> | ||
<div class="carousel-caption"> | ||
<h3>My slide {{i + 1}} title</h3> | ||
</div> | ||
<a href="https://www.google.fr/?q=Number+{{i+1}}" target="_blank" rel="nofollow noopener noreferrer"> | ||
<div class="picsum-img-wrapper"> | ||
<img [src]="img" alt="My image {{i + 1}} description"> | ||
</div> | ||
</a> | ||
</ng-template> | ||
</ngb-carousel> | ||
|
||
<hr> | ||
|
||
<div class="form-check"> | ||
<input type="checkbox" class="form-check-input" id="pauseOnHover" [(ngModel)]="pauseOnHover"> | ||
<label class="form-check-label" for="pauseOnHover">Pause on hover</label> | ||
</div> | ||
<div class="form-check"> | ||
<input type="checkbox" class="form-check-input" id="unpauseOnArrow" [(ngModel)]="unpauseOnArrow"> | ||
<label class="form-check-label" for="unpauseOnArrow">Unpause when clicking on arrows</label> | ||
</div> | ||
<div class="form-check"> | ||
<input type="checkbox" class="form-check-input" id="pauseOnIndicator" [(ngModel)]="pauseOnIndicator"> | ||
<label class="form-check-label" for="pauseOnIndicator">Pause when clicking on navigation indicator</label> | ||
</div> | ||
<button type="button" (click)="togglePaused()" class="btn btn-outline-dark btn-sm"> | ||
{{paused ? 'Cycle' : 'Pause' }} | ||
</button> |
14 changes: 14 additions & 0 deletions
14
demo/src/app/components/carousel/demos/pause/carousel-pause.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
import { NgbdCarouselPause } from './carousel-pause'; | ||
|
||
@NgModule({ | ||
imports: [BrowserModule, FormsModule, NgbModule], | ||
declarations: [NgbdCarouselPause], | ||
exports: [NgbdCarouselPause], | ||
bootstrap: [NgbdCarouselPause] | ||
}) | ||
export class NgbdCarouselPauseModule {} |
34 changes: 34 additions & 0 deletions
34
demo/src/app/components/carousel/demos/pause/carousel-pause.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { NgbCarousel, NgbSlideEvent, NgbSlideEventSource } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
|
||
@Component({selector: 'ngbd-carousel-pause', templateUrl: './carousel-pause.html'}) | ||
export class NgbdCarouselPause { | ||
images = [1, 2, 3, 4, 5, 6, 7].map(() => `https://picsum.photos/900/500?random&t=${Math.random()}`); | ||
|
||
paused = false; | ||
unpauseOnArrow = false; | ||
pauseOnIndicator = false; | ||
pauseOnHover = true; | ||
|
||
@ViewChild('carousel', {static : true}) carousel: NgbCarousel; | ||
|
||
togglePaused() { | ||
if (this.paused) { | ||
this.carousel.cycle(); | ||
} else { | ||
this.carousel.pause(); | ||
} | ||
this.paused = !this.paused; | ||
} | ||
|
||
onSlide(slideEvent: NgbSlideEvent) { | ||
if (this.unpauseOnArrow && slideEvent.paused && | ||
(slideEvent.source === NgbSlideEventSource.ARROW_LEFT || slideEvent.source === NgbSlideEventSource.ARROW_RIGHT)) { | ||
this.togglePaused(); | ||
} | ||
if (this.pauseOnIndicator && !slideEvent.paused && slideEvent.source === NgbSlideEventSource.INDICATOR) { | ||
this.togglePaused(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.