Skip to content

Commit 086d377

Browse files
MKirovaMKirova
authored andcommitted
Merge branch 'mkirova/grid-master-detail' of https://github.com/IgniteUI/igniteui-angular.git
2 parents 4dc6372 + 1c49aac commit 086d377

File tree

11 files changed

+306
-44
lines changed

11 files changed

+306
-44
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ All notable changes for each version of this project will be documented in this
6363
- `indicatorsOrientation` input is added, which can be used to set the position of indicators it can be top or bottom
6464
- `animationType` input is added, which can be used to set animation when changing slides
6565
- `indicatorTemplate` directive is added, which can be used to provide a custom indicator for carousel. If this property is not provided, a default indicator template will be used instead.
66+
- `nextButtonTemplate` directive is added, which is used to provide a custom next button template. If not provided, a default next button is used.
67+
- `prevButtonTemplate` directive is added, which is used to provide a custom previous button template. If not provided, a default previous button is used.
6668

6769
## 8.2.6
6870

projects/igniteui-angular/src/lib/carousel/README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,40 @@ Keyboard navigation will be enabled when the **IgxCarousel** component is focuse
4242
- `End` will focus the last slide inside the carousel view.
4343

4444
### Templates
45-
The **IgxCarousel** supports templating of its indicators
45+
The **IgxCarousel** supports templating indicators and navigation buttons
4646

4747
#### Defining item template:
4848
```html
4949
<igx-carousel #carousel>
5050
...
51-
<ng-template igxCarouselIndicator let-slide>
52-
<igx-icon *ngIf="slide.active" fontSet="material">brightness_7</igx-icon>
53-
<igx-icon *ngIf="!slide.active" fontSet="material">brightness_5</igx-icon>
54-
</ng-template>
51+
<ng-template igxCarouselIndicator let-slide>
52+
<igx-icon *ngIf="slide.active" fontSet="material">brightness_7</igx-icon>
53+
<igx-icon *ngIf="!slide.active" fontSet="material">brightness_5</igx-icon>
54+
</ng-template>
55+
</igx-carousel>
56+
```
57+
58+
#### Defining next button template:
59+
```html
60+
<igx-carousel #carousel>
61+
...
62+
<ng-template igxCarouselNextButton let-disabled>
63+
<button igxButton="fab" igxRipple="white" [disabled]="disabled">
64+
<igx-icon fontSet="material">add</igx-icon>
65+
</button>
66+
</ng-template>
67+
</igx-carousel>
68+
```
69+
70+
#### Defining previous button template:
71+
```html
72+
<igx-carousel #carousel>
73+
...
74+
<ng-template igxCarouselPrevButton let-disabled>
75+
<button igxButton="fab" igxRipple="white" [disabled]="disabled">
76+
<igx-icon fontSet="material">remove</igx-icon>
77+
</button>
78+
</ng-template>
5579
</igx-carousel>
5680
```
5781

projects/igniteui-angular/src/lib/carousel/carousel.component.html

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
</div>
66
</ng-template>
77

8+
<ng-template #defaultNextButton let-disabled>
9+
<a class="igx-nav-arrow"
10+
[class.igx-nav-arrow--disabled]="disabled"
11+
>
12+
<igx-icon fontSet="material">arrow_forward</igx-icon>
13+
</a>
14+
</ng-template>
15+
16+
<ng-template #defaultPrevButton let-disabled>
17+
<a class="igx-nav-arrow"
18+
[class.igx-nav-arrow--disabled]="disabled"
19+
>
20+
<igx-icon fontSet="material">arrow_back</igx-icon>
21+
</a>
22+
</ng-template>
23+
824

925
<div *ngIf="showIndicators" [ngClass]="indicatorsOrientationClass">
1026
<div *ngFor="let slide of slides"
@@ -24,12 +40,13 @@
2440
<ng-content></ng-content>
2541
</div>
2642

27-
<ng-container *ngIf="navigation">
28-
<a role="button" tabindex="0" class="igx-carousel__arrow--prev" (click)="prev()" [hidden]="!slides.length">
29-
<igx-icon fontSet="material">arrow_back</igx-icon>
30-
</a>
31-
<a role="button" tabindex="0" class="igx-carousel__arrow--next" (click)="next()" [hidden]="!slides.length">
32-
<igx-icon fontSet="material">arrow_forward</igx-icon>
33-
</a>
34-
</ng-container>
43+
<div *ngIf="navigation && slides.length" role="button" tabindex="0" class="igx-carousel__arrow--prev" (click)="prev()">
44+
<ng-container *ngTemplateOutlet="getPrevButtonTemplate; context: {$implicit: prevButtonDisabled};"></ng-container>
45+
</div>
46+
47+
<div *ngIf="navigation && slides.length" role="button" tabindex="0" class="igx-carousel__arrow--next" (click)="next()">
48+
<ng-container *ngTemplateOutlet="getNextButtonTemplate; context: {$implicit: nextButtonDisabled};"></ng-container>
49+
</div>
50+
51+
3552

projects/igniteui-angular/src/lib/carousel/carousel.component.spec.ts

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ describe('Carousel', () => {
515515
});
516516

517517
describe('Templates Tests: ', () => {
518-
it('verify that template can be defined in the markup', () => {
518+
it('verify that templates can be defined in the markup', () => {
519519
fixture = TestBed.createComponent(CarouselTemplateSetInMarkupTestComponent);
520520
carousel = fixture.componentInstance.carousel;
521521
fixture.detectChanges();
@@ -526,9 +526,15 @@ describe('Carousel', () => {
526526
const indicator = HelperTestFunctions.getIndicators(fixture)[index] as HTMLElement;
527527
expect(indicator.innerText).toEqual(index.toString());
528528
}
529+
530+
expect(HelperTestFunctions.getNextButtonArrow(fixture)).toBeNull();
531+
expect(HelperTestFunctions.getPreviousButtonArrow(fixture)).toBeNull();
532+
533+
expect(HelperTestFunctions.getNextButton(fixture).innerText).toEqual('next');
534+
expect(HelperTestFunctions.getPreviousButton(fixture).innerText).toEqual('prev');
529535
});
530536

531-
it('verify that template can be changed', () => {
537+
it('verify that templates can be changed', () => {
532538
fixture = TestBed.createComponent(CarouselTemplateSetInTypescriptTestComponent);
533539
carousel = fixture.componentInstance.carousel;
534540
fixture.detectChanges();
@@ -538,8 +544,12 @@ describe('Carousel', () => {
538544

539545
expect(HelperTestFunctions.getIndicators(fixture).length).toBe(4);
540546
expect(HelperTestFunctions.getIndicatorsDots(fixture).length).toBe(4);
547+
expect(HelperTestFunctions.getNextButtonArrow(fixture)).toBeDefined();
548+
expect(HelperTestFunctions.getPreviousButtonArrow(fixture)).toBeDefined();
541549

542550
carousel.indicatorTemplate = fixture.componentInstance.customIndicatorTemplate1;
551+
carousel.nextButtonTemplate = fixture.componentInstance.customNextTemplate;
552+
carousel.prevButtonTemplate = fixture.componentInstance.customPrevTemplate;
543553
fixture.detectChanges();
544554

545555
expect(HelperTestFunctions.getIndicators(fixture).length).toBe(4);
@@ -548,6 +558,11 @@ describe('Carousel', () => {
548558
const indicator = HelperTestFunctions.getIndicators(fixture)[index] as HTMLElement;
549559
expect(indicator.innerText).toEqual(index.toString());
550560
}
561+
expect(HelperTestFunctions.getNextButtonArrow(fixture)).toBeNull();
562+
expect(HelperTestFunctions.getPreviousButtonArrow(fixture)).toBeNull();
563+
564+
expect(HelperTestFunctions.getNextButton(fixture).innerText).toEqual('next');
565+
expect(HelperTestFunctions.getPreviousButton(fixture).innerText).toEqual('prev');
551566

552567
carousel.indicatorTemplate = fixture.componentInstance.customIndicatorTemplate2;
553568
fixture.detectChanges();
@@ -565,10 +580,14 @@ describe('Carousel', () => {
565580
}
566581

567582
carousel.indicatorTemplate = null;
583+
carousel.nextButtonTemplate = null;
584+
carousel.prevButtonTemplate = null;
568585
fixture.detectChanges();
569586

570587
expect(HelperTestFunctions.getIndicators(fixture).length).toBe(4);
571588
expect(HelperTestFunctions.getIndicatorsDots(fixture).length).toBe(4);
589+
expect(HelperTestFunctions.getNextButtonArrow(fixture)).toBeDefined();
590+
expect(HelperTestFunctions.getPreviousButtonArrow(fixture)).toBeDefined();
572591
});
573592
});
574593

@@ -704,8 +723,8 @@ describe('Carousel', () => {
704723
expect(carousel.total).toEqual(0);
705724
expect(HelperTestFunctions.getIndicatorsContainer(fixture)).toBeNull();
706725
expect(HelperTestFunctions.getIndicatorsContainer(fixture, CarouselIndicatorsOrientation.top)).toBeNull();
707-
expect(HelperTestFunctions.getNextButton(fixture).hidden).toBeTruthy();
708-
expect(HelperTestFunctions.getPreviousButton(fixture).hidden).toBeTruthy();
726+
expect(HelperTestFunctions.getNextButton(fixture)).toBeNull();
727+
expect(HelperTestFunctions.getPreviousButton(fixture)).toBeNull();
709728

710729
// add a slide
711730
fixture.componentInstance.addSlides();
@@ -724,6 +743,7 @@ describe('Carousel', () => {
724743
class HelperTestFunctions {
725744
public static NEXT_BUTTON_CLASS = '.igx-carousel__arrow--next';
726745
public static PRIV_BUTTON_CLASS = '.igx-carousel__arrow--prev';
746+
public static BUTTON_ARROW_CLASS = '.igx-nav-arrow';
727747
public static ACTIVE_SLIDE_CLASS = 'igx-slide--current';
728748
public static PREVIOUS_SLIDE_CLASS = 'igx-slide--previous';
729749
public static INDICATORS_TOP_CLASS = '.igx-carousel-indicators--top';
@@ -741,6 +761,16 @@ class HelperTestFunctions {
741761
return fixture.nativeElement.querySelector(HelperTestFunctions.PRIV_BUTTON_CLASS);
742762
}
743763

764+
public static getNextButtonArrow(fixture): HTMLElement {
765+
const next = HelperTestFunctions.getNextButton(fixture);
766+
return next.querySelector(HelperTestFunctions.BUTTON_ARROW_CLASS);
767+
}
768+
769+
public static getPreviousButtonArrow(fixture): HTMLElement {
770+
const prev = HelperTestFunctions.getPreviousButton(fixture);
771+
return prev.querySelector(HelperTestFunctions.BUTTON_ARROW_CLASS);
772+
}
773+
744774
public static getIndicatorsContainer(fixture, position = CarouselIndicatorsOrientation.bottom): HTMLElement {
745775
const carouselNative = fixture.nativeElement;
746776
if (position === CarouselIndicatorsOrientation.bottom) {
@@ -819,6 +849,14 @@ class CarouselAnimationsComponent {
819849
<ng-template igxCarouselIndicator let-slide>
820850
<span> {{slide.index}} </span>
821851
</ng-template>
852+
853+
<ng-template igxCarouselNextButton>
854+
<span>next</span>
855+
</ng-template>
856+
857+
<ng-template igxCarouselPrevButton>
858+
<span>prev</span>
859+
</ng-template>
822860
</igx-carousel>
823861
`
824862
})
@@ -837,6 +875,14 @@ class CarouselTemplateSetInMarkupTestComponent {
837875
<span *ngIf="slide.active"> {{slide.index}}: Active </span>
838876
</ng-template>
839877
878+
<ng-template #customNextTemplate>
879+
<span>next</span>
880+
</ng-template>
881+
882+
<ng-template #customPrevTemplate>
883+
<span>prev</span>
884+
</ng-template>
885+
840886
<igx-carousel #carousel [animationType]="'none'">
841887
<igx-slide><h3>Slide1</h3></igx-slide>
842888
<igx-slide><h3>Slide2</h3></igx-slide>
@@ -851,6 +897,10 @@ class CarouselTemplateSetInTypescriptTestComponent {
851897
public customIndicatorTemplate1;
852898
@ViewChild('customIndicatorTemplate2', { read: TemplateRef, static: false })
853899
public customIndicatorTemplate2;
900+
@ViewChild('customNextTemplate', { read: TemplateRef, static: false })
901+
public customNextTemplate;
902+
@ViewChild('customPrevTemplate', { read: TemplateRef, static: false })
903+
public customPrevTemplate;
854904
}
855905

856906
@Component({

0 commit comments

Comments
 (0)