Skip to content

Commit

Permalink
feat: add option not to display media error
Browse files Browse the repository at this point in the history
In the context of using gallery as a generic slider, where using custom
items is very probable, having a state for media loading error makes
little sense, so an option to turn it off is needed.
  • Loading branch information
daelmaak committed Oct 2, 2023
1 parent ec5018b commit 4182376
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
[arrows]="arrows"
[descriptions]="descriptions"
[errorText]="errorText"
[showErrors]="showErrors"
[mouseGestures]="mouseGestures"
[touchGestures]="touchGestures"
[clip]="clip"
Expand Down
4 changes: 4 additions & 0 deletions libs/gallery/src/lib/components/gallery/gallery.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export class GalleryComponent {
* Text to be shown when media loading failed
*/
@Input() errorText: string;
/**
* Display an error when the media contained in gallery item failed to load.
*/
@Input() showErrors = false;
/**
* Allow mouse swipes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('ViewerComponent', () => {
]);
viewer = new ViewerComponent(null, changeDetector, null, null);
viewer.items = [{ src: 'src1' }, { src: 'src2' }];
viewer.showErrors = true;
});

describe('failed', () => {
Expand Down
4 changes: 4 additions & 0 deletions libs/gallery/src/lib/components/viewer/viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class ViewerComponent implements OnChanges, OnInit, AfterViewInit {
@Input() selectedIndex: number;
@Input() descriptions: boolean;
@Input() errorText: string;
@Input() showErrors: boolean;
@Input() mouseGestures: boolean;
@Input() touchGestures: boolean;
@Input() counter: boolean;
Expand Down Expand Up @@ -254,6 +255,9 @@ export class ViewerComponent implements OnChanges, OnInit, AfterViewInit {
}

onItemErrored(item: GalleryItemInternal) {
if (!this.showErrors) {
return;
}
item._failed = true;
this._cd.detectChanges();
}
Expand Down

0 comments on commit 4182376

Please sign in to comment.