Skip to content

fix(alerts): after dismissing alert are not removing from DOM #3608 #3622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cypress/integration/alerts_page_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ describe('Alerts page test suite', () => {
});

it('alerts in dismissible example can all be closed and then resetting to default state', () => {
cy.get(alertsDemos[3]).find('alert').as('dismissAlert').each(($alert, i) => {
cy.get('@dismissAlert').eq(i).find('.close').click();
cy.get(alertsDemos[3]).find('alert').as('dismissAlert').each(($alert) => {
$alert.find('.close').click();
});

cy.get('@dismissAlert')
.should('not.to.have.descendants', 'div');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<alert type="success" dismissOnTimeout="5000">
<strong>Well done!</strong> You successfully read this important alert message.
</alert>

<p>If you missed alert on top of me, just press <code>Add more</code> button</p>
<p>If you missed alert under me, just press <code>Add more</code> button</p>
<div *ngFor="let alert of alerts">
<alert [type]="alert.type" [dismissOnTimeout]="alert.timeout">{{ alert.msg }}</alert>
<alert [type]="alert.type" [dismissOnTimeout]="alert.timeout" (onClosed)="onClosed(alert)">{{ alert.msg }}</alert>
</div>
<button type="button" class="btn btn-primary" (click)="add()">Add more</button>
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Component } from '@angular/core';
import { AlertComponent } from 'ngx-bootstrap/alert/alert.component';

@Component({
selector: 'demo-alert-timeout',
templateUrl: './dismiss-on-timeout.html'
})
export class DemoAlertTimeoutComponent {
alerts: any = [];
alerts: any[] = [{
type: 'success',
msg: `Well done! You successfully read this important alert message. (added: ${new Date().toLocaleTimeString()})`,
timeout: 5000
}];

add(): void {
this.alerts.push({
Expand All @@ -14,4 +19,8 @@ export class DemoAlertTimeoutComponent {
timeout: 5000
});
}

onClosed(dismissedAlert: AlertComponent): void {
this.alerts = this.alerts.filter(alert => alert !== dismissedAlert);
}
}
2 changes: 1 addition & 1 deletion demo/src/app/components/+alerts/demos/dismiss/dismiss.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div *ngFor="let alert of alerts">
<alert [type]="alert.type" [dismissible]="dismissible">{{ alert.msg }}</alert>
<alert [type]="alert.type" [dismissible]="dismissible" (onClosed)="onClosed(alert)">{{ alert.msg }}</alert>
</div>
<button type="button" class="btn btn-primary" (click)="dismissible = !dismissible">Toggle dismissible</button>
<button type="button" class="btn btn-primary" (click)="reset()">Reset</button>
9 changes: 7 additions & 2 deletions demo/src/app/components/+alerts/demos/dismiss/dismiss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Component } from '@angular/core';
})
export class DemoAlertDismissComponent {
dismissible = true;
alerts: any = [
defaultAlerts: any[] = [
{
type: 'success',
msg: `You successfully read this important alert message.`
Expand All @@ -20,8 +20,13 @@ export class DemoAlertDismissComponent {
msg: `Better check yourself, you're not looking too good.`
}
];
alerts = this.defaultAlerts;

reset(): void {
this.alerts = this.alerts.map((alert: any) => Object.assign({}, alert));
this.alerts = this.defaultAlerts;
}

onClosed(dismissedAlert: any): void {
this.alerts = this.alerts.filter(alert => alert !== dismissedAlert);
}
}
9 changes: 7 additions & 2 deletions src/alert/alert.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {
ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnInit,
Output
} from '@angular/core';
import { AlertConfig } from './alert.config';
Expand Down Expand Up @@ -33,7 +38,7 @@ export class AlertComponent implements OnInit {


classes = '';
dismissibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
dismissibleChange = new EventEmitter<boolean>();

constructor(_config: AlertConfig, private changeDetection: ChangeDetectorRef) {
Object.assign(this, _config);
Expand Down