Skip to content

Commit 1130d05

Browse files
committed
refactor(toast): utilize Overlay Service to display in DOM
1 parent 37f7c06 commit 1130d05

File tree

9 files changed

+184
-180
lines changed

9 files changed

+184
-180
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ All notable changes for each version of this project will be documented in this
3030
- `IgxOverlay`
3131
- The `PositionSettings` `target` property has been deprecated and moved to `OverlaySettings`.
3232
- An optional Point/HTML Element parameter `target` has been added to the `position()` method
33-
33+
- `IgxToast`
34+
- The component now utilizes the `IgxOverlayService` to position itself in the DOM.
35+
- An additional input property `outlet` has been added to allow users to specify custom Overlay Outlets using the `IgxOverlayOutletDirective`;
36+
- The `position` property now accepts values of type `IgxToastPosition` that work with strict templates.
37+
3438
## 10.1.0
3539

3640
### General

projects/igniteui-angular/src/lib/core/styles/components/toast/_toast-component.scss

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@
1111

1212
@extend %igx-toast-display !optional;
1313

14-
@include m(top) {
15-
@extend %igx-toast-display !optional;
16-
@extend %igx-toast--top !optional;
17-
}
18-
19-
@include m(middle) {
20-
@extend %igx-toast-display !optional;
21-
@extend %igx-toast--middle !optional;
22-
}
23-
24-
@include m(bottom) {
25-
@extend %igx-toast-display !optional;
26-
@extend %igx-toast--bottom !optional;
14+
@include m(active) {
15+
@extend %igx-toast--active !optional;
2716
}
2817
}

projects/igniteui-angular/src/lib/core/styles/components/toast/_toast-theme.scss

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,10 @@
102102
), $variant);
103103

104104
%igx-toast-display {
105-
position: fixed;
106-
display: flex;
105+
position: absolute;
106+
display: inline-flex;
107107
justify-content: center;
108108
align-items: center;
109-
left: 50%;
110-
transform: translate3d(-50%, 0, 0);
111109
margin: $margin;
112110
padding: $padding;
113111
min-width: $width;
@@ -117,23 +115,17 @@
117115
border-radius: --var($theme, 'border-radius');
118116
box-shadow: map-get($theme, 'shadow');
119117
backdrop-filter: blur(10px);
120-
opacity: 0;
121118
z-index: 999999;
119+
left: -999999px;
120+
top: -999999px;
121+
opacity: 0;
122122
}
123123

124-
%igx-toast--top {
125-
top: 0;
126-
margin-top: 16px;
127-
}
128-
129-
%igx-toast--middle {
130-
top: 50%;
131-
transform: translate3d(-50%, -50%, 0);
132-
}
133-
134-
%igx-toast--bottom {
135-
bottom: 0;
136-
margin-bottom: 16px;
124+
%igx-toast--active {
125+
position: relative;
126+
left: initial;
127+
top: initial;
128+
opacity: 1;
137129
}
138130
}
139131

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

Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
import {Component, ViewChild } from '@angular/core';
2-
import {async, TestBed, fakeAsync, tick, ComponentFixture} from '@angular/core/testing';
3-
import {By} from '@angular/platform-browser';
4-
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
5-
import {IgxToastComponent, IgxToastModule, IgxToastPosition} from './toast.component';
1+
import { Component, ViewChild } from '@angular/core';
2+
import {
3+
async,
4+
TestBed,
5+
fakeAsync,
6+
tick,
7+
ComponentFixture,
8+
} from '@angular/core/testing';
9+
import { By } from '@angular/platform-browser';
10+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
11+
import {
12+
IgxToastComponent,
13+
IgxToastModule,
14+
} from './toast.component';
615
import { configureTestSuite } from '../test-utils/configure-suite';
716

817
describe('IgxToast', () => {
918
configureTestSuite();
1019
beforeAll(async(() => {
1120
TestBed.configureTestingModule({
12-
declarations: [
13-
ToastInitializeTestComponent
14-
],
15-
imports: [
16-
BrowserAnimationsModule,
17-
IgxToastModule
18-
]
21+
declarations: [ToastInitializeTestComponent],
22+
imports: [BrowserAnimationsModule, IgxToastModule],
1923
}).compileComponents();
2024
}));
2125

2226
const baseClass = 'igx-toast';
23-
const classes = {
24-
top: `${baseClass}--top`,
25-
middle: `${baseClass}--middle`,
26-
bottom: `${baseClass}--bottom`,
27-
};
28-
27+
const activeClass = 'igx-toast--active';
2928
let fixture: ComponentFixture<ToastInitializeTestComponent>;
3029
let toast: IgxToastComponent;
3130

@@ -37,13 +36,14 @@ describe('IgxToast', () => {
3736
});
3837

3938
it('should properly initialize', () => {
40-
const domToast = fixture.debugElement.query(By.css(baseClass)).nativeElement;
39+
const domToast = fixture.debugElement.query(By.css(baseClass))
40+
.nativeElement;
4141
expect(toast.id).toContain('igx-toast-');
4242
expect(domToast.id).toContain('igx-toast-');
4343
expect(toast.displayTime).toBe(4000);
4444
expect(toast.autoHide).toBeTruthy();
4545
expect(toast.isVisible).toBeTruthy();
46-
expect(domToast.classList).toContain(classes.bottom);
46+
expect(domToast.classList).toContain(activeClass);
4747

4848
toast.id = 'customToast';
4949
fixture.detectChanges();
@@ -52,45 +52,17 @@ describe('IgxToast', () => {
5252
expect(domToast.id).toBe('customToast');
5353
});
5454

55-
it('should change toast position to middle', () => {
56-
toast.position = IgxToastPosition.Middle;
57-
fixture.detectChanges();
58-
const domToast = fixture.debugElement.query(By.css(baseClass)).nativeElement;
59-
60-
expect(domToast.classList).toContain(classes.middle);
61-
});
62-
63-
it('should change toast position to top', () => {
64-
toast.position = IgxToastPosition.Top;
65-
fixture.detectChanges();
66-
const domToast = fixture.debugElement.query(By.css(baseClass)).nativeElement;
67-
68-
expect(domToast.classList).toContain(classes.top);
69-
});
70-
71-
it('should change toast position to bottom', () => {
72-
toast.position = IgxToastPosition.Bottom;
73-
fixture.detectChanges();
74-
const domToast = fixture.debugElement.query(By.css(baseClass)).nativeElement;
75-
76-
expect(domToast.classList).not.toContain(classes.top);
77-
expect(domToast.classList).not.toContain(classes.middle);
78-
expect(domToast.classList).toContain(classes.bottom);
79-
});
80-
8155
it('should auto hide 1 second after it\'s open', fakeAsync(() => {
8256
toast.displayTime = 1000;
8357

8458
toast.show();
8559

8660
expect(toast.isVisible).toBeTruthy();
87-
expect(toast.animationState).toBe('visible');
8861
expect(toast.autoHide).toBeTruthy();
8962

9063
tick(1000);
9164

9265
expect(toast.isVisible).toBeFalsy();
93-
expect(toast.animationState).toBe('invisible');
9466
}));
9567

9668
it('should not auto hide after it\'s open', fakeAsync(() => {
@@ -100,13 +72,11 @@ describe('IgxToast', () => {
10072
toast.show();
10173

10274
expect(toast.isVisible).toBeTruthy();
103-
expect(toast.animationState).toBe('visible');
10475
expect(toast.autoHide).toBeFalsy();
10576

10677
tick(1000);
10778

10879
expect(toast.isVisible).toBeTruthy();
109-
expect(toast.animationState).toBe('visible');
11080
}));
11181

11282
it('visibility is updated by the toggle() method', () => {
@@ -117,7 +87,6 @@ describe('IgxToast', () => {
11787

11888
toast.show();
11989
expect(toast.isVisible).toBe(true);
120-
expect(toast.animationState).toBe('visible');
12190

12291
expect(toast.onShowing.emit).toHaveBeenCalledTimes(1);
12392
expect(toast.onShown.emit).toHaveBeenCalledTimes(1);
@@ -126,7 +95,6 @@ describe('IgxToast', () => {
12695

12796
toast.toggle();
12897
expect(toast.isVisible).toBe(false);
129-
expect(toast.animationState).toBe('invisible');
13098

13199
expect(toast.onShowing.emit).toHaveBeenCalledTimes(1);
132100
expect(toast.onShown.emit).toHaveBeenCalledTimes(1);
@@ -143,15 +111,13 @@ describe('IgxToast', () => {
143111
fixture.detectChanges();
144112

145113
expect(toast.isVisible).toBeTruthy();
146-
expect(toast.animationState).toBe('visible');
147114
expect(toast.autoHide).toBeFalsy();
148115
expect(toast.toastMessage).toBe('Custom Message');
149-
expect(fixture.nativeElement.querySelector('igx-toast:first-child').innerText).toBe('Custom Message');
150116
}));
151117
});
152118

153119
@Component({
154-
template: `<igx-toast #toast></igx-toast>`
120+
template: `<igx-toast #toast></igx-toast>`,
155121
})
156122
class ToastInitializeTestComponent {
157123
@ViewChild(IgxToastComponent, { static: true })

0 commit comments

Comments
 (0)