Skip to content

Commit 79e25a3

Browse files
committed
feat(toast): add ability to pass multiple classes to cssClass
references #7618
1 parent 466dea3 commit 79e25a3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/components/toast/test/basic/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class E2EPage {
4747
showLongToast() {
4848
const toast = this.toastCtrl.create({
4949
message: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea voluptatibus quibusdam eum nihil optio, ullam accusamus magni, nobis suscipit reprehenderit, sequi quam amet impedit. Accusamus dolorem voluptates laborum dolor obcaecati.',
50-
duration: 5000
50+
duration: 5000,
51+
cssClass: 'custom-class my-toast'
5152
});
5253

5354
toast.onDidDismiss(this.dismissHandler);

src/components/toast/toast-component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ import { ViewController } from '../nav/view-controller';
3535
},
3636
})
3737
export class ToastCmp implements AfterViewInit {
38-
private d: any;
38+
private d: {
39+
message?: string;
40+
cssClass?: string;
41+
duration?: number;
42+
showCloseButton?: boolean;
43+
closeButtonText?: string;
44+
dismissOnPageChange?: boolean;
45+
position?: string;
46+
};
3947
private descId: string;
4048
private dismissTimeout: number = undefined;
4149
private enabled: boolean;
@@ -53,7 +61,10 @@ export class ToastCmp implements AfterViewInit {
5361
this.d = params.data;
5462

5563
if (this.d.cssClass) {
56-
renderer.setElementClass(_elementRef.nativeElement, this.d.cssClass, true);
64+
this.d.cssClass.split(' ').forEach(cssClass => {
65+
// Make sure the class isn't whitespace, otherwise it throws exceptions
66+
if (cssClass.trim() !== '') renderer.setElementClass(_elementRef.nativeElement, cssClass, true);
67+
});
5768
}
5869

5970
this.id = (++toastIds);

0 commit comments

Comments
 (0)