Skip to content

Commit 96f899c

Browse files
SisIvanovakdinevsimeonoff
authored
fix(snackbar): use igxButton (#13584)
* fix(snackbar): use igxButton --------- Co-authored-by: Konstantin Dinev <[email protected]> Co-authored-by: Simeon Simeonoff <[email protected]>
1 parent 4f246c0 commit 96f899c

File tree

4 files changed

+28
-32
lines changed

4 files changed

+28
-32
lines changed

projects/igniteui-angular/src/lib/core/styles/components/snackbar/_snackbar-theme.scss

+14-24
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181

8282
$snackbar-min-height: rem(48px);
8383
$snackbar-padding: rem(7px) rem(24px);
84-
$snackbar-button-left-margin: rem(24px);
85-
$snackbar-button-line-height: rem(16px);
8684
$snackbar-button-font-weight: 600;
8785

8886
%igx-snackbar-display {
@@ -94,38 +92,30 @@
9492
min-height: $snackbar-min-height;
9593
padding: $snackbar-padding;
9694
margin: rem(8px);
95+
gap: rem(24px);
9796
color: var-get($theme, 'text-color');
9897
background: var-get($theme, 'background');
9998
backface-visibility: hidden;
10099
box-shadow: var-get($theme, 'shadow');
101100
border-radius: var-get($theme, 'border-radius');
102101
backdrop-filter: blur(8px);
103-
}
104102

105-
%igx-snackbar-message {
106-
@include animation('fade-in' .35s ease-out);
103+
[igxButton] {
104+
@include animation(fade-in .35s ease-out);
105+
--ig-size: 1;
106+
background: transparent;
107+
color: var-get($theme, 'button-color');
108+
-webkit-tap-highlight-color: transparent;
109+
box-shadow: none;
110+
}
107111
}
108112

109113
%igx-snackbar-button {
110-
background: transparent;
111-
color: var-get($theme, 'button-color');
112-
border: 0;
113-
line-height: $snackbar-button-line-height;
114-
margin-inline-start: $snackbar-button-left-margin;
115-
text-transform: uppercase;
116-
user-select: none;
117-
font-weight: $snackbar-button-font-weight;
118-
-webkit-tap-highlight-color: transparent;
119-
outline: none;
120-
transition: color .2s ease;
121-
font-size: inherit;
122-
font-family: inherit;
123-
cursor: pointer;
124-
@include animation('fade-in' .35s ease-out);
125-
126-
&:hover {
127-
color: var-get($theme, 'button-color');
128-
}
114+
display: contents;
115+
}
116+
117+
%igx-snackbar-message {
118+
@include animation(fade-in .35s ease-out);
129119
}
130120
}
131121

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
{{ textMessage }}
33
<ng-content></ng-content>
44
</div>
5-
<button type="button" class="igx-snackbar__button" igxRipple="white" *ngIf="actionText" (click)="triggerAction()">
5+
<div #customButton class="igx-snackbar__button">
6+
<ng-content select="[igxButton]"></ng-content>
7+
</div>
8+
<button *ngIf="!customButton.children.length && actionText" igxButton (click)="triggerAction()">
69
{{ actionText }}
710
</button>

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { By } from '@angular/platform-browser';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { IgxSnackbarComponent } from './snackbar.component';
66
import { configureTestSuite } from '../test-utils/configure-suite';
7-
import { HorizontalAlignment, PositionSettings, slideInLeft, slideInRight, VerticalAlignment } from 'igniteui-angular';
7+
import { HorizontalAlignment, IgxButtonDirective, PositionSettings, slideInLeft, slideInRight, VerticalAlignment } from 'igniteui-angular';
88
import { useAnimation } from '@angular/animations';
99

1010
describe('IgxSnackbar', () => {
@@ -215,13 +215,17 @@ describe('IgxSnackbar with custom content', () => {
215215
const customContent = fixture.debugElement.query(By.css('.igx-snackbar__content'));
216216
expect(customContent).toBeTruthy('Custom content is not found');
217217

218+
// Verify the custom button is displayed instead of the snackbar actionText
219+
const button = fixture.debugElement.query(By.css('.igx-button'));
220+
expect(button.nativeElement.innerText).toEqual('Read More');
221+
expect(button.nativeElement.innerText).not.toContain(snackbar.actionText);
222+
218223
// Verify the message is displayed on the left side of the custom content
219224
const messageElRect = messageEl.nativeElement.getBoundingClientRect();
220225
const customContentRect = customContent.nativeElement.getBoundingClientRect();
221226
expect(messageElRect.left <= customContentRect.left).toBe(true, 'The message is not on the left of the custom content');
222227

223228
// Verify the custom content element is on the left side of the button
224-
const button = fixture.debugElement.query(By.css('.igx-snackbar__button'));
225229
const buttonRect = button.nativeElement.getBoundingClientRect();
226230
expect(customContentRect.right <= buttonRect.left).toBe(true, 'The custom element is not on the left of the button');
227231
expect(messageElRect.right <= buttonRect.left).toBe(true, 'The button is not on the right side of the snackbar content');
@@ -263,9 +267,10 @@ class SnackbarInitializeTestComponent {
263267
@Component({
264268
template: `<igx-snackbar #snackbar [actionText]="text">
265269
<span class="igx-snackbar__content">Custom content</span>
270+
<button igxButton>Read More</button>
266271
</igx-snackbar>`,
267272
standalone: true,
268-
imports: [IgxSnackbarComponent]
273+
imports: [IgxSnackbarComponent, IgxButtonDirective]
269274
})
270275
class SnackbarCustomContentComponent {
271276
@ViewChild(IgxSnackbarComponent, { static: true }) public snackbar: IgxSnackbarComponent;

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ContainerPositionStrategy, GlobalPositionStrategy, HorizontalAlignment,
1414
PositionSettings, VerticalAlignment } from '../services/public_api';
1515
import { IgxNotificationsDirective } from '../directives/notification/notifications.directive';
1616
import { ToggleViewEventArgs } from '../directives/toggle/toggle.directive';
17+
import { IgxButtonDirective } from '../directives/button/button.directive';
1718

1819
let NEXT_ID = 0;
1920
/**
@@ -37,7 +38,7 @@ let NEXT_ID = 0;
3738
selector: 'igx-snackbar',
3839
templateUrl: 'snackbar.component.html',
3940
standalone: true,
40-
imports: [NgIf]
41+
imports: [NgIf, IgxButtonDirective]
4142
})
4243
export class IgxSnackbarComponent extends IgxNotificationsDirective
4344
implements OnInit {
@@ -102,7 +103,6 @@ export class IgxSnackbarComponent extends IgxNotificationsDirective
102103
*/
103104
@Output() public animationDone = new EventEmitter<ToggleViewEventArgs>();
104105

105-
106106
/**
107107
* Get the position and animation settings used by the snackbar.
108108
* ```typescript
@@ -160,7 +160,6 @@ export class IgxSnackbarComponent extends IgxNotificationsDirective
160160
this.textMessage = message;
161161
}
162162

163-
164163
this.strategy = this.outlet ? new ContainerPositionStrategy(this.positionSettings)
165164
: new GlobalPositionStrategy(this.positionSettings);
166165
super.open();
@@ -203,4 +202,3 @@ export class IgxSnackbarComponent extends IgxNotificationsDirective
203202
});
204203
}
205204
}
206-

0 commit comments

Comments
 (0)