Skip to content

Commit

Permalink
fix: close a notification on detach (#3834)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored May 12, 2022
1 parent 921f61e commit c79a2ae
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dev/notification.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Notification</title>
<script type="module" src="./common.js"></script>
</head>

<body>
<vaadin-notification position="middle" duration="0" theme="success"></vaadin-notification>

<script type="module">
import '@vaadin/notification';

const notification = document.querySelector('vaadin-notification');
notification.renderer = root => root.textContent = 'Financial report generated';
notification.open();
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions packages/notification/src/vaadin-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ class Notification extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
processTemplates(this);
}

/** @protected */
disconnectedCallback() {
super.disconnectedCallback();
this.opened = false;
}

/**
* Requests an update for the content of the notification.
* While performing the update, it invokes the renderer passed in the `renderer` property.
Expand Down
6 changes: 6 additions & 0 deletions packages/notification/test/notification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ describe('vaadin-notification', () => {
expect(notification._card.getAttribute('id')).to.be.null;
});

it('should close on detach', () => {
expect(notification.opened).to.be.true;
notification.remove();
expect(notification.opened).to.be.false;
});

describe('vaadin-notification-container', () => {
it('should be in the body when notification opens', () => {
expect(document.body.querySelectorAll('vaadin-notification-container').length).to.be.equal(1);
Expand Down

0 comments on commit c79a2ae

Please sign in to comment.