• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 12072443768

28 Nov 2024 04:16PM UTC coverage: 91.621%. Remained the same
12072443768

Pull #15120

github

web-flow
fix(excel-style-filtering): reset filter value (#15090)

* fix(esf): show filters based on column name

* fix(esf-custom-dialog): filter expressionsList by column name

* chore(*): revert changes after branch retarget

---------

Co-authored-by: RadoMirchev <radoslav.p.mirchev@gmail.com>
Co-authored-by: Konstantin Dinev <kdinev@mail.bw.edu>
Co-authored-by: Galina Edinakova <gedinakova@infragistics.com>
Pull Request #15120: Mass Merge 19.0.x to master

12969 of 15202 branches covered (85.31%)

54 of 65 new or added lines in 14 files covered. (83.08%)

111 existing lines in 6 files now uncovered.

26309 of 28715 relevant lines covered (91.62%)

34021.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.21
/projects/igniteui-angular/src/lib/carousel/carousel.component.ts
1
import { NgIf, NgClass, NgFor, NgTemplateOutlet } from '@angular/common';
2
import {
3
    AfterContentInit,
4
    ChangeDetectorRef,
5
    Component,
6
    ContentChild,
7
    ContentChildren,
8
    ElementRef,
9
    EventEmitter,
10
    HostBinding,
11
    HostListener,
12
    Inject,
13
    Injectable,
14
    Input,
15
    IterableChangeRecord,
16
    IterableDiffer,
17
    IterableDiffers,
18
    OnDestroy,
19
    Output,
20
    QueryList,
21
    TemplateRef,
22
    ViewChild,
23
    ViewChildren,
24
    booleanAttribute
25
} from '@angular/core';
26
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
27
import { merge, Subject } from 'rxjs';
28
import { takeUntil } from 'rxjs/operators';
29
import { CarouselResourceStringsEN, ICarouselResourceStrings } from '../core/i18n/carousel-resources';
30
import { first, IBaseEventArgs, last, PlatformUtil } from '../core/utils';
31
import { IgxAngularAnimationService } from '../services/animation/angular-animation-service';
32
import { AnimationService } from '../services/animation/animation';
33
import { Direction, IgxCarouselComponentBase } from './carousel-base';
34
import { IgxCarouselIndicatorDirective, IgxCarouselNextButtonDirective, IgxCarouselPrevButtonDirective } from './carousel.directives';
35
import { IgxSlideComponent } from './slide.component';
36
import { IgxIconComponent } from '../icon/icon.component';
37
import { IgxButtonDirective } from '../directives/button/button.directive';
38
import { getCurrentResourceStrings } from '../core/i18n/resources';
39
import { HammerGesturesManager } from '../core/touch';
40
import { CarouselAnimationType, CarouselIndicatorsOrientation } from './enums';
41
import { IgxDirectionality } from '../services/direction/directionality';
42

43
let NEXT_ID = 0;
2✔
44

45

46
@Injectable()
47
export class CarouselHammerConfig extends HammerGestureConfig {
2✔
48
    public override overrides = {
×
49
        pan: { direction: HammerGesturesManager.Hammer?.DIRECTION_HORIZONTAL }
50
    };
51
}
52
/**
53
 * **Ignite UI for Angular Carousel** -
54
 * [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/carousel.html)
55
 *
56
 * The Ignite UI Carousel is used to browse or navigate through a collection of slides. Slides can contain custom
57
 * content such as images or cards and be used for things such as on-boarding tutorials or page-based interfaces.
58
 * It can be used as a separate fullscreen element or inside another component.
59
 *
60
 * Example:
61
 * ```html
62
 * <igx-carousel>
63
 *   <igx-slide>
64
 *     <h3>First Slide Header</h3>
65
 *     <p>First slide Content</p>
66
 *   <igx-slide>
67
 *   <igx-slide>
68
 *     <h3>Second Slide Header</h3>
69
 *     <p>Second Slide Content</p>
70
 * </igx-carousel>
71
 * ```
72
 */
73
@Component({
74
    providers: [
75
        {
76
            provide: HAMMER_GESTURE_CONFIG,
77
            useClass: CarouselHammerConfig
78
        }
79
    ],
80
    selector: 'igx-carousel',
81
    templateUrl: 'carousel.component.html',
82
    styles: [`
83
    :host {
84
        display: block;
85
        outline-style: none;
86
    }`],
87
    imports: [IgxButtonDirective, IgxIconComponent, NgIf, NgClass, NgFor, NgTemplateOutlet]
88
})
89

90
export class IgxCarouselComponent extends IgxCarouselComponentBase implements OnDestroy, AfterContentInit {
2✔
91

92
    /**
93
     * Sets the `id` of the carousel.
94
     * If not set, the `id` of the first carousel component will be `"igx-carousel-0"`.
95
     * ```html
96
     * <igx-carousel id="my-first-carousel"></igx-carousel>
97
     * ```
98
     *
99
     * @memberof IgxCarouselComponent
100
     */
101
    @HostBinding('attr.id')
102
    @Input()
103
    public id = `igx-carousel-${NEXT_ID++}`;
43✔
104
    /**
105
     * Returns the `role` attribute of the carousel.
106
     * ```typescript
107
     * let carouselRole =  this.carousel.role;
108
     * ```
109
     *
110
     * @memberof IgxCarouselComponent
111
     */
112
    @HostBinding('attr.role') public role = 'region';
43✔
113

114
    /** @hidden */
115
    @HostBinding('attr.aria-roledescription')
116
    public roleDescription = 'carousel';
43✔
117

118
    /** @hidden */
119
    @HostBinding('attr.aria-labelledby')
120
    public get labelId() {
121
        return this.showIndicatorsLabel ? `${this.id}-label` : null;
410✔
122
    }
123

124
    /** @hidden */
125
    @HostBinding('class.igx-carousel--vertical')
126
        public get isVertical(): boolean {
127
                return this.vertical;
406✔
128
        }
129

130
    /**
131
     * Returns the class of the carousel component.
132
     * ```typescript
133
     * let class =  this.carousel.cssClass;
134
     * ```
135
     *
136
     * @memberof IgxCarouselComponent
137
     */
138
    @HostBinding('class.igx-carousel')
139
    public cssClass = 'igx-carousel';
43✔
140

141
    /**
142
     * Gets the `touch-action` style of the `list item`.
143
     * ```typescript
144
     * let touchAction = this.listItem.touchAction;
145
     * ```
146
     */
147
    @HostBinding('style.touch-action')
148
    public get touchAction() {
149
        return this.gesturesSupport ? 'pan-y' : 'auto';
406✔
150
    }
151

152
    /**
153
     * Sets whether the carousel should `loop` back to the first slide after reaching the last slide.
154
     * Default value is `true`.
155
     * ```html
156
     * <igx-carousel [loop]="false"></igx-carousel>
157
     * ```
158
     *
159
     * @memberOf IgxCarouselComponent
160
     */
161
    @Input({ transform: booleanAttribute }) public loop = true;
43✔
162

163
    /**
164
     * Sets whether the carousel will `pause` the slide transitions on user interactions.
165
     * Default value is `true`.
166
     * ```html
167
     *  <igx-carousel [pause]="false"></igx-carousel>
168
     * ```
169
     *
170
     * @memberOf IgxCarouselComponent
171
     */
172
    @Input({ transform: booleanAttribute }) public pause = true;
43✔
173

174
    /**
175
     * Controls whether the carousel should render the left/right `navigation` buttons.
176
     * Default value is `true`.
177
     * ```html
178
     * <igx-carousel [navigation]="false"></igx-carousel>
179
     * ```
180
     *
181
     * @memberOf IgxCarouselComponent
182
     */
183
    @Input({ transform: booleanAttribute }) public navigation = true;
43✔
184

185
    /**
186
     * Controls whether the carousel should render the indicators.
187
     * Default value is `true`.
188
     * ```html
189
     * <igx-carousel [indicators]="false"></igx-carousel>
190
     * ```
191
     *
192
     * @memberOf IgxCarouselComponent
193
     */
194
    @Input({ transform: booleanAttribute }) public indicators = true;
43✔
195

196

197
    /**
198
     * Controls whether the carousel has vertical alignment.
199
     * Default value is `false`.
200
     * ```html
201
     * <igx-carousel [vertical]="true"></igx-carousel>
202
     * ```
203
     *
204
     * @memberOf IgxCarouselComponent
205
     */
206
    @Input({ transform: booleanAttribute }) public override vertical = false;
43✔
207

208
    /**
209
     * Controls whether the carousel should support keyboard navigation.
210
     * Default value is `false`.
211
     * ```html
212
     * <igx-carousel [keyboardSupport]="true"></igx-carousel>
213
     * ```
214
     *
215
     * @memberOf IgxCarouselComponent
216
     * @deprecated in version 18.2.0.
217
     */
218
    @Input({ transform: booleanAttribute }) public keyboardSupport = false;
43✔
219

220
    /**
221
     * Controls whether the carousel should support gestures.
222
     * Default value is `true`.
223
     * ```html
224
     * <igx-carousel [gesturesSupport]="false"></igx-carousel>
225
     * ```
226
     *
227
     * @memberOf IgxCarouselComponent
228
     */
229
    @Input({ transform: booleanAttribute }) public gesturesSupport = true;
43✔
230

231
    /**
232
     * Controls the maximum indexes that can be shown.
233
     * Default value is `5`.
234
     * ```html
235
     * <igx-carousel [maximumIndicatorsCount]="10"></igx-carousel>
236
     * ```
237
     *
238
     * @memberOf IgxCarouselComponent
239
     */
240
    @Input() public maximumIndicatorsCount = 5;
43✔
241

242
    /**
243
     * Gets/sets the display mode of carousel indicators. It can be top or bottom.
244
     * Default value is `bottom`.
245
     * ```html
246
     * <igx-carousel indicatorsOrientation='top'>
247
     * <igx-carousel>
248
     * ```
249
     *
250
     * @memberOf IgxSlideComponent
251
     */
252
    @Input() public indicatorsOrientation: CarouselIndicatorsOrientation = CarouselIndicatorsOrientation.bottom;
43✔
253

254
    /**
255
     * Gets/sets the animation type of carousel.
256
     * Default value is `slide`.
257
     * ```html
258
     * <igx-carousel animationType='none'>
259
     * <igx-carousel>
260
     * ```
261
     *
262
     * @memberOf IgxSlideComponent
263
     */
264
    @Input() public override animationType: CarouselAnimationType = CarouselAnimationType.slide;
43✔
265

266
    /**
267
     * The custom template, if any, that should be used when rendering carousel indicators
268
     *
269
     * ```typescript
270
     * // Set in typescript
271
     * const myCustomTemplate: TemplateRef<any> = myComponent.customTemplate;
272
     * myComponent.carousel.indicatorTemplate = myCustomTemplate;
273
     * ```
274
     * ```html
275
     * <!-- Set in markup -->
276
     *  <igx-carousel #carousel>
277
     *      ...
278
     *      <ng-template igxCarouselIndicator let-slide>
279
     *         <igx-icon *ngIf="slide.active">brightness_7</igx-icon>
280
     *         <igx-icon *ngIf="!slide.active">brightness_5</igx-icon>
281
     *      </ng-template>
282
     *  </igx-carousel>
283
     * ```
284
     */
285
    @ContentChild(IgxCarouselIndicatorDirective, { read: TemplateRef, static: false })
286
    public indicatorTemplate: TemplateRef<any> = null;
43✔
287

288
    /**
289
     * The custom template, if any, that should be used when rendering carousel next button
290
     *
291
     * ```typescript
292
     * // Set in typescript
293
     * const myCustomTemplate: TemplateRef<any> = myComponent.customTemplate;
294
     * myComponent.carousel.nextButtonTemplate = myCustomTemplate;
295
     * ```
296
     * ```html
297
     * <!-- Set in markup -->
298
     *  <igx-carousel #carousel>
299
     *      ...
300
     *      <ng-template igxCarouselNextButton let-disabled>
301
     *          <button type="button" igxButton="fab" igxRipple="white" [disabled]="disabled">
302
     *              <igx-icon name="add"></igx-icon>
303
     *          </button>
304
     *      </ng-template>
305
     *  </igx-carousel>
306
     * ```
307
     */
308
    @ContentChild(IgxCarouselNextButtonDirective, { read: TemplateRef, static: false })
309
    public nextButtonTemplate: TemplateRef<any> = null;
43✔
310

311
    /**
312
     * The custom template, if any, that should be used when rendering carousel previous button
313
     *
314
     * ```typescript
315
     * // Set in typescript
316
     * const myCustomTemplate: TemplateRef<any> = myComponent.customTemplate;
317
     * myComponent.carousel.prevButtonTemplate = myCustomTemplate;
318
     * ```
319
     * ```html
320
     * <!-- Set in markup -->
321
     *  <igx-carousel #carousel>
322
     *      ...
323
     *      <ng-template igxCarouselPrevButton let-disabled>
324
     *          <button type="button" igxButton="fab" igxRipple="white" [disabled]="disabled">
325
     *              <igx-icon name="remove"></igx-icon>
326
     *          </button>
327
     *      </ng-template>
328
     *  </igx-carousel>
329
     * ```
330
     */
331
    @ContentChild(IgxCarouselPrevButtonDirective, { read: TemplateRef, static: false })
332
    public prevButtonTemplate: TemplateRef<any> = null;
43✔
333

334
    /**
335
     * The collection of `slides` currently in the carousel.
336
     * ```typescript
337
     * let slides: QueryList<IgxSlideComponent> = this.carousel.slides;
338
     * ```
339
     *
340
     * @memberOf IgxCarouselComponent
341
     */
342
    @ContentChildren(IgxSlideComponent)
343
    public slides: QueryList<IgxSlideComponent>;
344

345
    /**
346
     * An event that is emitted after a slide transition has happened.
347
     * Provides references to the `IgxCarouselComponent` and `IgxSlideComponent` as event arguments.
348
     * ```html
349
     * <igx-carousel (slideChanged)="slideChanged($event)"></igx-carousel>
350
     * ```
351
     *
352
     * @memberOf IgxCarouselComponent
353
     */
354
    @Output() public slideChanged = new EventEmitter<ISlideEventArgs>();
43✔
355

356
    /**
357
     * An event that is emitted after a slide has been added to the carousel.
358
     * Provides references to the `IgxCarouselComponent` and `IgxSlideComponent` as event arguments.
359
     * ```html
360
     * <igx-carousel (slideAdded)="slideAdded($event)"></igx-carousel>
361
     * ```
362
     *
363
     * @memberOf IgxCarouselComponent
364
     */
365
    @Output() public slideAdded = new EventEmitter<ISlideEventArgs>();
43✔
366

367
    /**
368
     * An event that is emitted after a slide has been removed from the carousel.
369
     * Provides references to the `IgxCarouselComponent` and `IgxSlideComponent` as event arguments.
370
     * ```html
371
     * <igx-carousel (slideRemoved)="slideRemoved($event)"></igx-carousel>
372
     * ```
373
     *
374
     * @memberOf IgxCarouselComponent
375
     */
376
    @Output() public slideRemoved = new EventEmitter<ISlideEventArgs>();
43✔
377

378
    /**
379
     * An event that is emitted after the carousel has been paused.
380
     * Provides a reference to the `IgxCarouselComponent` as an event argument.
381
     * ```html
382
     * <igx-carousel (carouselPaused)="carouselPaused($event)"></igx-carousel>
383
     * ```
384
     *
385
     * @memberOf IgxCarouselComponent
386
     */
387
    @Output() public carouselPaused = new EventEmitter<IgxCarouselComponent>();
43✔
388

389
    /**
390
     * An event that is emitted after the carousel has resumed transitioning between `slides`.
391
     * Provides a reference to the `IgxCarouselComponent` as an event argument.
392
     * ```html
393
     * <igx-carousel (carouselPlaying)="carouselPlaying($event)"></igx-carousel>
394
     * ```
395
     *
396
     * @memberOf IgxCarouselComponent
397
     */
398
    @Output() public carouselPlaying = new EventEmitter<IgxCarouselComponent>();
43✔
399

400
    @ViewChild('defaultIndicator', { read: TemplateRef, static: true })
401
    private defaultIndicator: TemplateRef<any>;
402

403
    @ViewChild('defaultNextButton', { read: TemplateRef, static: true })
404
    private defaultNextButton: TemplateRef<any>;
405

406
    @ViewChild('defaultPrevButton', { read: TemplateRef, static: true })
407
    private defaultPrevButton: TemplateRef<any>;
408

409
    @ViewChildren('indicators', { read: ElementRef })
410
    private _indicators: QueryList<ElementRef<HTMLDivElement>>;
411

412
    /**
413
     * @hidden
414
     * @internal
415
     */
416
    public stoppedByInteraction: boolean;
417
    protected override currentItem: IgxSlideComponent;
418
    protected override previousItem: IgxSlideComponent;
419
    private _interval: number;
420
    private _resourceStrings = getCurrentResourceStrings(CarouselResourceStringsEN);
43✔
421
    private lastInterval: any;
422
    private playing: boolean;
423
    private destroyed: boolean;
424
    private destroy$ = new Subject<any>();
43✔
425
    private differ: IterableDiffer<IgxSlideComponent> | null = null;
43✔
426
    private incomingSlide: IgxSlideComponent;
427
    private _hasKeyboardFocusOnIndicators = false;
43✔
428

429
    /**
430
     * An accessor that sets the resource strings.
431
     * By default it uses EN resources.
432
     */
433
    @Input()
434
    public set resourceStrings(value: ICarouselResourceStrings) {
435
        this._resourceStrings = Object.assign({}, this._resourceStrings, value);
×
436
    }
437

438
    /**
439
     * An accessor that returns the resource strings.
440
     */
441
    public get resourceStrings(): ICarouselResourceStrings {
442
        return this._resourceStrings;
3,952✔
443
    }
444

445
    /** @hidden */
446
    public get getIndicatorTemplate(): TemplateRef<any> {
447
        if (this.indicatorTemplate) {
1,574✔
448
            return this.indicatorTemplate;
24✔
449
        }
450
        return this.defaultIndicator;
1,550✔
451
    }
452

453
    /** @hidden */
454
    public get getNextButtonTemplate(): TemplateRef<any> {
455
        if (this.nextButtonTemplate) {
400✔
456
            return this.nextButtonTemplate;
6✔
457
        }
458

459
        return this.defaultNextButton
394✔
460
    }
461

462
    /** @hidden */
463
    public get getPrevButtonTemplate(): TemplateRef<any> {
464
        if (this.prevButtonTemplate) {
400✔
465
            return this.prevButtonTemplate;
6✔
466
        }
467

468
        return this.defaultPrevButton
394✔
469
    }
470

471
    /** @hidden */
472
    public get indicatorsClass() {
473
        return {
402✔
474
            ['igx-carousel-indicators--focused']: this._hasKeyboardFocusOnIndicators,
475
            [`igx-carousel-indicators--${this.indicatorsOrientation}`]: true
476
        };
477
    }
478

479
    /** @hidden */
480
    public get showIndicators(): boolean {
481
        return this.indicators && this.total <= this.maximumIndicatorsCount && this.total > 0;
406✔
482
    }
483

484
    /** @hidden */
485
    public get showIndicatorsLabel(): boolean {
486
        return this.indicators && this.total > this.maximumIndicatorsCount;
816✔
487
    }
488

489
    /** @hidden */
490
    public get getCarouselLabel() {
491
        return `${this.current + 1} ${this.resourceStrings.igx_carousel_of} ${this.total}`;
4✔
492
    }
493

494
    /**
495
     * Returns the total number of `slides` in the carousel.
496
     * ```typescript
497
     * let slideCount =  this.carousel.total;
498
     * ```
499
     *
500
     * @memberOf IgxCarouselComponent
501
     */
502
    public get total(): number {
503
        return this.slides?.length;
11,248✔
504
    }
505

506
    /**
507
     * The index of the slide being currently shown.
508
     * ```typescript
509
     * let currentSlideNumber =  this.carousel.current;
510
     * ```
511
     *
512
     * @memberOf IgxCarouselComponent
513
     */
514
    public get current(): number {
515
        return !this.currentItem ? 0 : this.currentItem.index;
3,391✔
516
    }
517

518
    /**
519
     * Returns a boolean indicating if the carousel is playing.
520
     * ```typescript
521
     * let isPlaying =  this.carousel.isPlaying;
522
     * ```
523
     *
524
     * @memberOf IgxCarouselComponent
525
     */
526
    public get isPlaying(): boolean {
527
        return this.playing;
31✔
528
    }
529

530
    /**
531
     * Returns а boolean indicating if the carousel is destroyed.
532
     * ```typescript
533
     * let isDestroyed =  this.carousel.isDestroyed;
534
     * ```
535
     *
536
     * @memberOf IgxCarouselComponent
537
     */
538
    public get isDestroyed(): boolean {
539
        return this.destroyed;
1✔
540
    }
541
    /**
542
     * Returns a reference to the carousel element in the DOM.
543
     * ```typescript
544
     * let nativeElement =  this.carousel.nativeElement;
545
     * ```
546
     *
547
     * @memberof IgxCarouselComponent
548
     */
549
    public get nativeElement(): any {
550
        return this.element.nativeElement;
24✔
551
    }
552

553
    /**
554
     * Returns the time `interval` in milliseconds before the slide changes.
555
     * ```typescript
556
     * let timeInterval = this.carousel.interval;
557
     * ```
558
     *
559
     * @memberof IgxCarouselComponent
560
     */
561
    @Input()
562
    public get interval(): number {
563
        return this._interval;
3,818✔
564
    }
565

566
    /**
567
     * Sets the time `interval` in milliseconds before the slide changes.
568
     * If not set, the carousel will not change `slides` automatically.
569
     * ```html
570
     * <igx-carousel [interval]="1000"></igx-carousel>
571
     * ```
572
     *
573
     * @memberof IgxCarouselComponent
574
     */
575
    public set interval(value: number) {
576
        this._interval = +value;
29✔
577
        this.restartInterval();
29✔
578
    }
579

580
    constructor(
581
        cdr: ChangeDetectorRef,
582
        private element: ElementRef,
43✔
583
        private iterableDiffers: IterableDiffers,
43✔
584
        @Inject(IgxAngularAnimationService) animationService: AnimationService,
585
        private platformUtil: PlatformUtil,
43✔
586
        private dir: IgxDirectionality
43✔
587
    ) {
588
        super(animationService, cdr);
43✔
589
        this.differ = this.iterableDiffers.find([]).create(null);
43✔
590
    }
591

592

593
    /** @hidden */
594
    @HostListener('keydown.arrowright', ['$event'])
595
    public onKeydownArrowRight(event) {
596
        if (this.keyboardSupport) {
8✔
597
            event.preventDefault();
5✔
598
            this.next();
5✔
599
            this.focusElement();
5✔
600
        }
601
    }
602

603
    /** @hidden */
604
    @HostListener('keydown.arrowleft', ['$event'])
605
    public onKeydownArrowLeft(event) {
606
        if (this.keyboardSupport) {
5✔
607
            event.preventDefault();
2✔
608
            this.prev();
2✔
609
            this.focusElement();
2✔
610
        }
611
    }
612

613
    /** @hidden */
614
    @HostListener('tap', ['$event'])
615
    public onTap(event) {
616
        // play pause only when tap on slide
617
        if (event.target && event.target.classList.contains('igx-slide')) {
4✔
618
            if (this.isPlaying) {
4✔
619
                if (this.pause) {
1✔
620
                    this.stoppedByInteraction = true;
1✔
621
                }
622
                this.stop();
1✔
623
            } else if (this.stoppedByInteraction) {
3✔
624
                this.play();
1✔
625
            }
626
        }
627
    }
628

629
    /** @hidden */
630
    @HostListener('keydown.home', ['$event'])
631
    public onKeydownHome(event) {
632
        if (this.keyboardSupport && this.slides.length > 0) {
4✔
633
            event.preventDefault();
1✔
634
            this.slides.first.active = true;
1✔
635
            this.focusElement();
1✔
636
        }
637
    }
638

639
    /** @hidden */
640
    @HostListener('keydown.end', ['$event'])
641
    public onKeydownEnd(event) {
642
        if (this.keyboardSupport && this.slides.length > 0) {
4✔
643
            event.preventDefault();
1✔
644
            this.slides.last.active = true;
1✔
645
            this.focusElement();
1✔
646
        }
647
    }
648

649
    /** @hidden */
650
    @HostListener('mouseenter')
651
    public onMouseEnter() {
652
        if (this.pause && this.isPlaying) {
2✔
653
            this.stoppedByInteraction = true;
1✔
654
        }
655
        this.stop();
2✔
656
    }
657

658
    /** @hidden */
659
    @HostListener('mouseleave')
660
    public onMouseLeave() {
661
        if (this.stoppedByInteraction) {
2✔
662
            this.play();
1✔
663
        }
664
    }
665

666
    /** @hidden */
667
    @HostListener('panleft', ['$event'])
668
    public onPanLeft(event) {
669
        if (!this.vertical) {
7✔
670
            this.pan(event);
5✔
671
        }
672
    }
673

674
    /** @hidden */
675
    @HostListener('panright', ['$event'])
676
    public onPanRight(event) {
677
        if (!this.vertical) {
7✔
678
            this.pan(event);
5✔
679
        }
680
    }
681

682
    /** @hidden */
683
    @HostListener('panup', ['$event'])
684
    public onPanUp(event) {
685
        if (this.vertical) {
5✔
686
            this.pan(event);
3✔
687
        }
688
    }
689

690
    /** @hidden */
691
    @HostListener('pandown', ['$event'])
692
    public onPanDown(event) {
693
        if (this.vertical) {
5✔
694
            this.pan(event);
3✔
695
        }
696
    }
697

698
    /**
699
     * @hidden
700
     */
701
    @HostListener('panend', ['$event'])
702
    public onPanEnd(event) {
703
        if (!this.gesturesSupport) {
24✔
704
            return;
2✔
705
        }
706
        event.preventDefault();
22✔
707

708
        const slideSize = this.vertical
22✔
709
            ? this.currentItem.nativeElement.offsetHeight
710
            : this.currentItem.nativeElement.offsetWidth;
711
        const panOffset = (slideSize / 1000);
22✔
712
        const eventDelta = this.vertical ? event.deltaY : event.deltaX;
22✔
713
        const delta = Math.abs(eventDelta) + panOffset < slideSize ? Math.abs(eventDelta) : slideSize - panOffset;
22!
714
        const velocity = Math.abs(event.velocity);
22✔
715
        this.resetSlideStyles(this.currentItem);
22✔
716
        if (this.incomingSlide) {
22✔
717
            this.resetSlideStyles(this.incomingSlide);
12✔
718
            if (slideSize / 2 < delta || velocity > 1) {
12✔
719
                this.incomingSlide.direction = eventDelta < 0 ? Direction.NEXT : Direction.PREV;
8✔
720
                this.incomingSlide.previous = false;
8✔
721

722
                this.animationPosition = this.animationType === CarouselAnimationType.fade ?
8!
723
                    delta / slideSize : (slideSize - delta) / slideSize;
724

725
                if (velocity > 1) {
8✔
726
                    this.newDuration = this.defaultAnimationDuration / velocity;
4✔
727
                }
728
                this.incomingSlide.active = true;
8✔
729
            } else {
730
                this.currentItem.direction = eventDelta > 0 ? Direction.NEXT : Direction.PREV;
4✔
731
                this.previousItem = this.incomingSlide;
4✔
732
                this.previousItem.previous = true;
4✔
733
                this.animationPosition = this.animationType === CarouselAnimationType.fade ?
4!
734
                    Math.abs((slideSize - delta) / slideSize) : delta / slideSize;
735
                this.playAnimations();
4✔
736
            }
737
        }
738

739
        if (this.stoppedByInteraction) {
22!
UNCOV
740
            this.play();
×
741
        }
742
    }
743

744
    /** @hidden */
745
    public ngAfterContentInit() {
746
        this.slides.changes
43✔
747
            .pipe(takeUntil(this.destroy$))
748
            .subscribe((change: QueryList<IgxSlideComponent>) => this.initSlides(change));
13✔
749

750
        this.initSlides(this.slides);
43✔
751
    }
752

753
    /** @hidden */
754
    public ngOnDestroy() {
755
        this.destroy$.next(true);
44✔
756
        this.destroy$.complete();
44✔
757
        this.destroyed = true;
44✔
758
        if (this.lastInterval) {
44✔
759
            clearInterval(this.lastInterval);
25✔
760
        }
761
    }
762

763
    /** @hidden */
764
    public handleKeydownPrev(event: KeyboardEvent): void {
765
        if (this.platformUtil.isActivationKey(event)) {
2✔
766
            event.preventDefault();
2✔
767
            this.prev();
2✔
768
        }
769
    }
770

771
    /** @hidden */
772
    public handleKeydownNext(event: KeyboardEvent): void {
773
        if (this.platformUtil.isActivationKey(event)) {
2✔
774
            event.preventDefault();
2✔
775
            this.next();
2✔
776
        }
777
    }
778

779
    /** @hidden */
780
    public handleKeyUp(event: KeyboardEvent): void {
781
        if (event.key === this.platformUtil.KEYMAP.TAB) {
5✔
782
            this._hasKeyboardFocusOnIndicators = true;
5✔
783
        }
784
    }
785

786
    /** @hidden */
787
    public handleFocusOut(event: FocusEvent): void {
788
        const target = event.relatedTarget as HTMLElement;
7✔
789

790
        if (!target || !target.classList.contains('igx-carousel-indicators__indicator')) {
7✔
791
            this._hasKeyboardFocusOnIndicators = false;
1✔
792
        }
793
    }
794

795
    /** @hidden */
796
    public handleClick(): void {
797
        this._hasKeyboardFocusOnIndicators = false;
1✔
798
    }
799

800
    /** @hidden */
801
    public handleKeydown(event: KeyboardEvent): void {
802
        if (this.keyboardSupport) {
8!
UNCOV
803
            return;
×
804
        }
805
        const { key } = event;
8✔
806
        const slides = this.slides.toArray();
8✔
807

808
        switch (key) {
8✔
809
            case this.platformUtil.KEYMAP.ARROW_LEFT:
810
                this.dir.rtl ? this.next() : this.prev();
2✔
811
                break;
2✔
812
            case this.platformUtil.KEYMAP.ARROW_RIGHT:
813
                this.dir.rtl ? this.prev() : this.next();
2✔
814
                break;
2✔
815
            case this.platformUtil.KEYMAP.HOME:
816
                event.preventDefault();
2✔
817
                this.select(this.dir.rtl ? last(slides) : first(slides));
2✔
818
                break;
2✔
819
            case this.platformUtil.KEYMAP.END:
820
                event.preventDefault();
2✔
821
                this.select(this.dir.rtl ? first(slides) : last(slides));
2✔
822
                break;
2✔
823
        }
824

825
        this.indicatorsElements[this.current].nativeElement.focus();
8✔
826
    }
827

828
    /**
829
     * Returns the slide corresponding to the provided `index` or null.
830
     * ```typescript
831
     * let slide1 =  this.carousel.get(1);
832
     * ```
833
     *
834
     * @memberOf IgxCarouselComponent
835
     */
836
    public get(index: number): IgxSlideComponent {
837
        return this.slides.find((slide) => slide.index === index);
7,341✔
838
    }
839

840
    /**
841
     * Adds a new slide to the carousel.
842
     * ```typescript
843
     * this.carousel.add(newSlide);
844
     * ```
845
     *
846
     * @memberOf IgxCarouselComponent
847
     */
848
    public add(slide: IgxSlideComponent) {
849
        const newSlides = this.slides.toArray();
3✔
850
        newSlides.push(slide);
3✔
851
        this.slides.reset(newSlides);
3✔
852
        this.slides.notifyOnChanges();
3✔
853
    }
854

855
    /**
856
     * Removes a slide from the carousel.
857
     * ```typescript
858
     * this.carousel.remove(slide);
859
     * ```
860
     *
861
     * @memberOf IgxCarouselComponent
862
     */
863
    public remove(slide: IgxSlideComponent) {
864
        if (slide && slide === this.get(slide.index)) { // check if the requested slide for delete is present in the carousel
4✔
865
            const newSlides = this.slides.toArray();
4✔
866
            newSlides.splice(slide.index, 1);
4✔
867
            this.slides.reset(newSlides);
4✔
868
            this.slides.notifyOnChanges();
4✔
869
        }
870
    }
871

872
    /**
873
     * Kicks in a transition for a given slide with a given `direction`.
874
     * ```typescript
875
     * this.carousel.select(this.carousel.get(2), Direction.NEXT);
876
     * ```
877
     *
878
     * @memberOf IgxCarouselComponent
879
     */
880
    public select(slide: IgxSlideComponent, direction: Direction = Direction.NONE) {
12✔
881
        if (slide && slide !== this.currentItem) {
3,129✔
882
            slide.direction = direction;
3,128✔
883
            slide.active = true;
3,128✔
884
        }
885
    }
886

887
    /**
888
     * Transitions to the next slide in the carousel.
889
     * ```typescript
890
     * this.carousel.next();
891
     * ```
892
     *
893
     * @memberOf IgxCarouselComponent
894
     */
895
    public next() {
896
        const index = this.getNextIndex();
3,106✔
897

898
        if (index === 0 && !this.loop) {
3,106✔
899
            this.stop();
1✔
900
            return;
1✔
901
        }
902
        return this.select(this.get(index), Direction.NEXT);
3,105✔
903
    }
904

905
    /**
906
     * Transitions to the previous slide in the carousel.
907
     * ```typescript
908
     * this.carousel.prev();
909
     * ```
910
     *
911
     * @memberOf IgxCarouselComponent
912
     */
913
    public prev() {
914
        const index = this.getPrevIndex();
13✔
915

916
        if (!this.loop && index === this.total - 1) {
13✔
917
            this.stop();
1✔
918
            return;
1✔
919
        }
920
        return this.select(this.get(index), Direction.PREV);
12✔
921
    }
922

923
    /**
924
     * Resumes playing of the carousel if in paused state.
925
     * No operation otherwise.
926
     * ```typescript
927
     * this.carousel.play();
928
     * }
929
     * ```
930
     *
931
     * @memberOf IgxCarouselComponent
932
     */
933
    public play() {
934
        if (!this.playing) {
61✔
935
            this.playing = true;
47✔
936
            this.carouselPlaying.emit(this);
47✔
937
            this.restartInterval();
47✔
938
            this.stoppedByInteraction = false;
47✔
939
        }
940
    }
941

942
    /**
943
     * Stops slide transitions if the `pause` option is set to `true`.
944
     * No operation otherwise.
945
     * ```typescript
946
     *  this.carousel.stop();
947
     * }
948
     * ```
949
     *
950
     * @memberOf IgxCarouselComponent
951
     */
952
    public stop() {
953
        if (this.pause) {
9✔
954
            this.playing = false;
9✔
955
            this.carouselPaused.emit(this);
9✔
956
            this.resetInterval();
9✔
957
        }
958
    }
959

960
    protected getPreviousElement(): HTMLElement {
961
        return this.previousItem.nativeElement;
2✔
962
    }
963

964
    protected getCurrentElement(): HTMLElement {
965
        return this.currentItem.nativeElement;
3✔
966
    }
967

968
    private resetInterval() {
969
        if (this.lastInterval) {
138✔
970
            clearInterval(this.lastInterval);
70✔
971
            this.lastInterval = null;
70✔
972
        }
973
    }
974

975
    private restartInterval() {
976
        this.resetInterval();
129✔
977

978
        if (!isNaN(this.interval) && this.interval > 0 && this.platformUtil.isBrowser) {
129✔
979
            this.lastInterval = setInterval(() => {
97✔
980
                const tick = +this.interval;
3,087✔
981
                if (this.playing && this.total && !isNaN(tick) && tick > 0) {
3,087!
982
                    this.next();
3,087✔
983
                } else {
UNCOV
984
                    this.stop();
×
985
                }
986
            }, this.interval);
987
        }
988
    }
989

990
    /** @hidden */
991
    public get nextButtonDisabled() {
992
        return !this.loop && this.current === (this.total - 1);
800✔
993
    }
994

995
    /** @hidden */
996
    public get prevButtonDisabled() {
997
        return !this.loop && this.current === 0;
800✔
998
    }
999

1000
    private get indicatorsElements() {
1001
        return this._indicators.toArray();
8✔
1002
    }
1003

1004
    private focusElement() {
1005
        const focusedElement = document.activeElement;
9✔
1006

1007
        if (focusedElement.classList.contains('igx-carousel-indicators__indicator')) {
9!
UNCOV
1008
            this.indicatorsElements[this.current].nativeElement.focus();
×
1009
        } else {
1010
            this.focusSlideElement();
9✔
1011
        }
1012
    }
1013

1014
    private getNextIndex(): number {
1015
        return (this.current + 1) % this.total;
3,114✔
1016
    }
1017

1018
    private getPrevIndex(): number {
1019
        return this.current - 1 < 0 ? this.total - 1 : this.current - 1;
21✔
1020
    }
1021

1022
    private resetSlideStyles(slide: IgxSlideComponent) {
1023
        slide.nativeElement.style.transform = '';
38✔
1024
        slide.nativeElement.style.opacity = '';
38✔
1025
    }
1026

1027
    private pan(event) {
1028
        const slideSize = this.vertical
16✔
1029
            ? this.currentItem.nativeElement.offsetHeight
1030
            : this.currentItem.nativeElement.offsetWidth;
1031
        const panOffset = (slideSize / 1000);
16✔
1032
        const delta = this.vertical ? event.deltaY : event.deltaX;
16✔
1033
        const index = delta < 0 ? this.getNextIndex() : this.getPrevIndex();
16✔
1034
        const offset = delta < 0 ? slideSize + delta : -slideSize + delta;
16✔
1035

1036
        if (!this.gesturesSupport || event.isFinal || Math.abs(delta) + panOffset >= slideSize) {
16✔
1037
            return;
2✔
1038
        }
1039

1040
        if (!this.loop && ((this.current === 0 && delta > 0) || (this.current === this.total - 1 && delta < 0))) {
14✔
1041
            this.incomingSlide = null;
2✔
1042
            return;
2✔
1043
        }
1044

1045
        event.preventDefault();
12✔
1046
        if (this.isPlaying) {
12!
UNCOV
1047
            this.stoppedByInteraction = true;
×
1048
            this.stop();
×
1049
        }
1050

1051
        if (this.previousItem && this.previousItem.previous) {
12✔
1052
            this.previousItem.previous = false;
4✔
1053
        }
1054
        this.finishAnimations();
12✔
1055

1056
        if (this.incomingSlide) {
12✔
1057
            if (index !== this.incomingSlide.index) {
8✔
1058
                this.resetSlideStyles(this.incomingSlide);
4✔
1059
                this.incomingSlide.previous = false;
4✔
1060
                this.incomingSlide = this.get(index);
4✔
1061
            }
1062
        } else {
1063
            this.incomingSlide = this.get(index);
4✔
1064
        }
1065
        this.incomingSlide.previous = true;
12✔
1066

1067
        if (this.animationType === CarouselAnimationType.fade) {
12!
UNCOV
1068
            this.currentItem.nativeElement.style.opacity = `${Math.abs(offset) / slideSize}`;
×
1069
        } else {
1070
            this.currentItem.nativeElement.style.transform = this.vertical
12✔
1071
                ? `translateY(${delta}px)`
1072
                : `translateX(${delta}px)`;
1073
            this.incomingSlide.nativeElement.style.transform = this.vertical
12✔
1074
                ? `translateY(${offset}px)`
1075
                : `translateX(${offset}px)`;
1076
        }
1077
    }
1078

1079
    private unsubscriber(slide: IgxSlideComponent) {
1080
        return merge(this.destroy$, slide.isDestroyed);
179✔
1081
    }
1082

1083
    private onSlideActivated(slide: IgxSlideComponent) {
1084
        if (slide.active && slide !== this.currentItem) {
103✔
1085
            if (slide.direction === Direction.NONE) {
53✔
1086
                const newIndex = slide.index;
11✔
1087
                slide.direction = newIndex > this.current ? Direction.NEXT : Direction.PREV;
11✔
1088
            }
1089

1090
            if (this.currentItem) {
53✔
1091
                if (this.previousItem && this.previousItem.previous) {
41!
UNCOV
1092
                    this.previousItem.previous = false;
×
1093
                }
1094
                this.currentItem.direction = slide.direction;
41✔
1095
                this.currentItem.active = false;
41✔
1096

1097
                this.previousItem = this.currentItem;
41✔
1098
                this.currentItem = slide;
41✔
1099
                this.triggerAnimations();
41✔
1100
            } else {
1101
                this.currentItem = slide;
12✔
1102
            }
1103
            this.slideChanged.emit({ carousel: this, slide });
53✔
1104
            this.restartInterval();
53✔
1105
        }
1106
    }
1107

1108

1109
    private finishAnimations() {
1110
        if (this.animationStarted(this.leaveAnimationPlayer)) {
12!
UNCOV
1111
            this.leaveAnimationPlayer.finish();
×
1112
        }
1113

1114
        if (this.animationStarted(this.enterAnimationPlayer)) {
12!
UNCOV
1115
            this.enterAnimationPlayer.finish();
×
1116
        }
1117
    }
1118

1119
    private initSlides(change: QueryList<IgxSlideComponent>) {
1120
        const diff = this.differ.diff(change.toArray());
56✔
1121
        if (diff) {
56✔
1122
            this.slides.reduce((any, c, ind) => c.index = ind, 0); // reset slides indexes
214✔
1123
            diff.forEachAddedItem((record: IterableChangeRecord<IgxSlideComponent>) => {
56✔
1124
                const slide = record.item;
179✔
1125
                slide.total = this.total;
179✔
1126
                this.slideAdded.emit({ carousel: this, slide });
179✔
1127
                if (slide.active) {
179✔
1128
                    this.currentItem = slide;
17✔
1129
                }
1130
                slide.activeChange.pipe(takeUntil(this.unsubscriber(slide))).subscribe(() => this.onSlideActivated(slide));
179✔
1131
            });
1132

1133
            diff.forEachRemovedItem((record: IterableChangeRecord<IgxSlideComponent>) => {
56✔
1134
                const slide = record.item;
10✔
1135
                this.slideRemoved.emit({ carousel: this, slide });
10✔
1136
                if (slide.active) {
10✔
1137
                    slide.active = false;
3✔
1138
                    this.currentItem = this.get(slide.index < this.total ? slide.index : this.total - 1);
3✔
1139
                }
1140
            });
1141

1142
            this.updateSlidesSelection();
56✔
1143
        }
1144
    }
1145

1146
    private updateSlidesSelection() {
1147
        if (this.platformUtil.isBrowser) {
56✔
1148
            requestAnimationFrame(() => {
56✔
1149
                if (this.currentItem) {
56✔
1150
                    this.currentItem.active = true;
32✔
1151
                    const activeSlides = this.slides.filter(slide => slide.active && slide.index !== this.currentItem.index);
126✔
1152
                    activeSlides.forEach(slide => slide.active = false);
32✔
1153
                } else if (this.total) {
24✔
1154
                    this.slides.first.active = true;
23✔
1155
                }
1156
                this.play();
56✔
1157
            });
1158
        }
1159
    }
1160
    private focusSlideElement() {
1161
        if (this.leaveAnimationPlayer) {
9!
UNCOV
1162
            this.leaveAnimationPlayer.animationEnd
×
1163
                .pipe(takeUntil(this.destroy$))
1164
                .subscribe(() => {
UNCOV
1165
                    this.slides.find(s => s.active).nativeElement.focus();
×
1166
                });
1167
        } else {
1168
            requestAnimationFrame(() => this.slides.find(s => s.active).nativeElement.focus());
35✔
1169
        }
1170
    }
1171

1172
}
1173

1174
export interface ISlideEventArgs extends IBaseEventArgs {
1175
    carousel: IgxCarouselComponent;
1176
    slide: IgxSlideComponent;
1177
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc