Skip to content

Commit 7589b6f

Browse files
authored
Merge pull request #7716 from IgniteUI/ddincheva/igxToast
IgxToast `show` method take a message parameter
2 parents fdb6355 + 523f92b commit 7589b6f

File tree

7 files changed

+96
-17
lines changed

7 files changed

+96
-17
lines changed

CHANGELOG.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ All notable changes for each version of this project will be documented in this
55
## 10.1.0
66

77
### New Features
8-
- `IgxColumn`
8+
- `IgxColumn`
99
- Added `byHeader` parameter to the `autosize` method which specifies if the autosizing should be based only on the header content width.
10+
- `IgxToast`
11+
- `message` property has been deprecated. You can place the *message text* in the toast content or pass it as parameter to `show` method instead.
12+
- An optional string parameter `message` has been added to `show()` method.
13+
- `IgxSnackbar`
14+
- `message` property has been deprecated. You can place the *message text* in the snackbar content or pass it as parameter to `show` method instead.
15+
- An optional string parameter `message` has been added to `show()` method.
1016

1117
## 10.0.0
1218

@@ -16,9 +22,9 @@ All notable changes for each version of this project will be documented in this
1622
- `igx-select`, `igx-combo`, `igx-drop-down`
1723
- **Behavioral Change** - The select, combo, and dropdown items now have display block and text-overflow ellipsis enabled by default.
1824
- `IgxTransaction` - The `onStateUpdate` now emits with information of its origin. The emitted value is of type `StateUpdateEvent`, which has two properties:
19-
- `origin` - it can vary within the values of the `TransactionEventOrigin` interface;
25+
- `origin` - it can vary within the values of the `TransactionEventOrigin` interface;
2026
- `actions` - contains information about the transactions, that caused the emission of the event.
21-
- `IgxPaginator` - The input `overlaySettings` was introduced, which allows applying custom overlay settings for the component.
27+
- `IgxPaginator` - The input `overlaySettings` was introduced, which allows applying custom overlay settings for the component.
2228

2329
### New Features
2430
- `IgxGrid`
@@ -162,9 +168,9 @@ All notable changes for each version of this project will be documented in this
162168
```typescript
163169
public pinningConfiguration: IPinningConfig = { columns: ColumnPinningPosition.End };
164170
```
165-
- Added new properties for paging:
166-
- `totalRecords` set to alter the pages count based on total remote records. Keep in mind that If you are using paging and all the data is passed to the grid, the value of totalRecords property will be set by default to the length of the provided data source. If totalRecords is set, it will take precedent over the default length based on the data source.
167-
- `pagingMode` - accepts `GridPagingMode` enumeration. If the paging mode is set to remote the grid will not paginate the passed data source, if the paging mode is set to local (which is the default value) the grid will paginate the data source based on the page, perPage and totalRecords values.
171+
- Added new properties for paging:
172+
- `totalRecords` set to alter the pages count based on total remote records. Keep in mind that If you are using paging and all the data is passed to the grid, the value of totalRecords property will be set by default to the length of the provided data source. If totalRecords is set, it will take precedent over the default length based on the data source.
173+
- `pagingMode` - accepts `GridPagingMode` enumeration. If the paging mode is set to remote the grid will not paginate the passed data source, if the paging mode is set to local (which is the default value) the grid will paginate the data source based on the page, perPage and totalRecords values.
168174
- Added functionality for column selection.
169175
- `columnSelection` property has been added. It accepts GridSelection mode enumeration. Grid selection mode could be none, single or multiple.
170176
- `selected` property has been added to the IgxColumnComponent; Allows you to set whether the column is selected.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="igx-snackbar" *ngIf="isVisible" (@slideInOut.start)="snackbarAnimationStarted($event)" (@slideInOut.done)="snackbarAnimationDone($event)"
22
[@slideInOut]="isVisible">
33
<div class="igx-snackbar__message" [@fadeInOut]="isVisible">
4-
{{ message }}
4+
{{ snackbarMessage }}
55
<ng-content></ng-content>
66
</div>
77
<button class="igx-snackbar__button" igxRipple="white" *ngIf="actionText" [@fadeInOut] (click)="triggerAction()">

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ describe('IgxSnackbar', () => {
3131

3232
it('should properly initialize properties', () => {
3333
expect(snackbar.id).toContain('igx-snackbar-');
34-
expect(snackbar.message).toBeUndefined();
3534
expect(snackbar.actionText).toBeUndefined();
3635
expect(snackbar.displayTime).toBe(4000);
3736
expect(snackbar.autoHide).toBeTruthy();
@@ -115,8 +114,7 @@ describe('IgxSnackbar with custom content', () => {
115114

116115
it('should display a message, a custom content element and a button', () => {
117116
fixture.componentInstance.text = 'Undo';
118-
snackbar.message = 'Item shown';
119-
snackbar.isVisible = true;
117+
snackbar.show('Item shown');
120118
fixture.detectChanges();
121119

122120
const messageEl = fixture.debugElement.query(By.css('.igx-snackbar__message'));
@@ -136,6 +134,25 @@ describe('IgxSnackbar with custom content', () => {
136134
expect(customContentRect.right <= buttonRect.left).toBe(true, 'The custom element is not on the left of the button');
137135
expect(messageElRect.right <= buttonRect.left).toBe(true, 'The button is not on the right side of the snackbar content');
138136
});
137+
138+
it('should be able to set a message though show method', () => {
139+
snackbar.autoHide = false;
140+
fixture.componentInstance.text = 'Retry';
141+
fixture.detectChanges();
142+
143+
snackbar.show('The message was not send. Would you like to retry?');
144+
fixture.detectChanges();
145+
146+
expect(fixture.nativeElement.querySelector('.igx-snackbar__message').innerText)
147+
.toBe('The message was not send. Would you like to retry? Custom content');
148+
149+
snackbar.show('Another Message?!');
150+
fixture.detectChanges();
151+
152+
expect(snackbar.isVisible).toBe(true);
153+
expect(fixture.nativeElement.querySelector('.igx-snackbar__message').innerText)
154+
.toBe('Another Message?! Custom content');
155+
});
139156
});
140157

141158
@Component({

projects/igniteui-angular/src/lib/snackbar/snackbar.component.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Output
1616
} from '@angular/core';
1717
import { fadeIn, fadeOut, slideInBottom, slideOutBottom } from '../animations/main';
18+
import { DeprecateProperty } from '../core/deprecateDecorators';
1819

1920
let NEXT_ID = 0;
2021
/**
@@ -101,6 +102,7 @@ export class IgxSnackbarComponent {
101102
@HostBinding('attr.id')
102103
@Input()
103104
public id = `igx-snackbar-${NEXT_ID++}`;
105+
104106
/**
105107
* Sets/gets the `message` attribute.
106108
* ```html
@@ -110,7 +112,15 @@ export class IgxSnackbarComponent {
110112
* let message = this.snackbar.message;
111113
* ```
112114
*/
113-
@Input() public message: string;
115+
@DeprecateProperty(`'message' property is deprecated.
116+
You can use place the message in the snackbar content or pass a message parameter to the show method instead.`)
117+
@Input()
118+
public set message(value: string) {
119+
this.snackbarMessage = value;
120+
}
121+
public get message() {
122+
return this.snackbarMessage;
123+
}
114124

115125
/**
116126
* Enables/Disables the visibility of the snackbar.
@@ -182,6 +192,13 @@ export class IgxSnackbarComponent {
182192
* ```
183193
*/
184194
@Output() public animationDone = new EventEmitter<AnimationEvent>();
195+
196+
/**
197+
* @hidden
198+
* @internal
199+
*/
200+
snackbarMessage = '';
201+
185202
/**
186203
* @hidden
187204
*/
@@ -195,8 +212,9 @@ export class IgxSnackbarComponent {
195212
* this.snackbar.show();
196213
* ```
197214
*/
198-
public show(): void {
215+
public show(message?: string): void {
199216
clearTimeout(this.timeoutId);
217+
if (message !== undefined) { this.snackbarMessage = message; }
200218
setTimeout(this.timeoutId);
201219
this.isVisible = true;
202220

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<ng-content></ng-content>
2-
<span>{{ message }}</span>
2+
<span>{{ toastMessage }}</span>
33

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,22 @@ describe('IgxToast', () => {
132132
expect(toast.onShown.emit).toHaveBeenCalledTimes(1);
133133
expect(toast.onHiding.emit).toHaveBeenCalledTimes(1);
134134
expect(toast.onHidden.emit).toHaveBeenCalledTimes(1);
135-
136135
});
136+
137+
it('can set message through show method', fakeAsync(() => {
138+
toast.displayTime = 100;
139+
toast.autoHide = false;
140+
141+
toast.show('Custom Message');
142+
tick(100);
143+
fixture.detectChanges();
144+
145+
expect(toast.isVisible).toBeTruthy();
146+
expect(toast.animationState).toBe('visible');
147+
expect(toast.autoHide).toBeFalsy();
148+
expect(toast.toastMessage).toBe('Custom Message');
149+
expect(fixture.nativeElement.querySelector('igx-toast:first-child').innerText).toBe('Custom Message');
150+
}));
137151
});
138152

139153
@Component({

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { animate, state, style, transition, trigger } from '@angular/animations';
22
import { CommonModule } from '@angular/common';
3+
import { DeprecateProperty } from '../core/deprecateDecorators';
34
import {
45
Component,
56
ElementRef,
@@ -205,10 +206,26 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
205206
public isVisibleChange = new EventEmitter<boolean>();
206207

207208
/**
208-
* @hidden
209+
* @deprecated Place your message in the toast content instead.
210+
* Sets/gets the message that will be shown by the toast.
211+
* ```html
212+
* <igx-toast [message] = "Notification"></igx-toast>
213+
* ```
214+
* ```typescript
215+
* let toastMessage = this.toast.message;
216+
* ```
217+
* @memberof IgxToastComponent
209218
*/
219+
@DeprecateProperty(`'message' property is deprecated.
220+
You can use place the message in the toast content or pass it as parameter to the show method instead.`)
210221
@Input()
211-
public message = '';
222+
public set message(value: string) {
223+
this.toastMessage = value;
224+
}
225+
226+
public get message() {
227+
return this.toastMessage;
228+
}
212229

213230
/**
214231
* Sets/gets the position of the toast.
@@ -235,6 +252,12 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
235252
return this.elementRef.nativeElement;
236253
}
237254

255+
/**
256+
* @hidden
257+
* @internal
258+
*/
259+
toastMessage = '';
260+
238261
/**
239262
* @hidden
240263
*/
@@ -252,8 +275,9 @@ export class IgxToastComponent implements IToggleView, OnInit, OnDestroy {
252275
* ```
253276
* @memberof IgxToastComponent
254277
*/
255-
public show(): void {
278+
public show(message?: string): void {
256279
clearInterval(this.timeoutId);
280+
if (message !== undefined) { this.toastMessage = message; }
257281
this.onShowing.emit(this);
258282
this.isVisible = true;
259283
this.animationState = 'visible';

0 commit comments

Comments
 (0)