Skip to content

Commit

Permalink
fix(alerts): after dismissing alert are not removing from DOM #3608 (#…
Browse files Browse the repository at this point in the history
…3622)

Fix removing alert from DOM after its dismissing

Close #3608
  • Loading branch information
IraErshova authored and valorkin committed Feb 22, 2018
1 parent 7201fcd commit 479778a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
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

0 comments on commit 479778a

Please sign in to comment.