Skip to content

Commit 256ef92

Browse files
authored
refactor: include notification container into the overlay stack (#8198)
1 parent ab28efb commit 256ef92

File tree

7 files changed

+83
-35
lines changed

7 files changed

+83
-35
lines changed

packages/notification/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@polymer/polymer": "^3.0.0",
4242
"@vaadin/component-base": "24.6.0-beta1",
4343
"@vaadin/lit-renderer": "24.6.0-beta1",
44+
"@vaadin/overlay": "24.6.0-beta1",
4445
"@vaadin/vaadin-lumo-styles": "24.6.0-beta1",
4546
"@vaadin/vaadin-material-styles": "24.6.0-beta1",
4647
"@vaadin/vaadin-themable-mixin": "24.6.0-beta1",

packages/notification/src/vaadin-notification-mixin.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Constructor } from '@open-wc/dedupe-mixin';
22
import type { OverlayClassMixinClass } from '@vaadin/component-base/src/overlay-class-mixin.js';
3+
import type { OverlayStackMixinClass } from '@vaadin/overlay/src/vaadin-overlay-stack-mixin.js';
34
import type { ThemePropertyMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
45
import type { Notification } from './vaadin-notification.js';
56

@@ -21,7 +22,7 @@ export type NotificationRenderer = (root: HTMLElement, notification: Notificatio
2122
*/
2223
export declare function NotificationContainerMixin<T extends Constructor<HTMLElement>>(
2324
base: T,
24-
): Constructor<NotificationContainerMixinClass> & T;
25+
): Constructor<NotificationContainerMixinClass> & Constructor<OverlayStackMixinClass> & T;
2526

2627
export declare class NotificationContainerMixinClass {
2728
/**

packages/notification/src/vaadin-notification-mixin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import { isTemplateResult } from 'lit/directive-helpers.js';
88
import { isIOS } from '@vaadin/component-base/src/browser-utils.js';
99
import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
1010
import { processTemplates } from '@vaadin/component-base/src/templates.js';
11+
import { OverlayStackMixin } from '@vaadin/overlay/src/vaadin-overlay-stack-mixin.js';
1112
import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
1213

1314
/**
1415
* A mixin providing common notification container functionality.
1516
*
1617
* @polymerMixin
18+
* @mixes OverlayStackMixin
1719
*/
1820
export const NotificationContainerMixin = (superClass) =>
19-
class extends superClass {
21+
class extends OverlayStackMixin(superClass) {
2022
static get properties() {
2123
return {
2224
/**
@@ -362,6 +364,8 @@ export const NotificationMixin = (superClass) =>
362364
return;
363365
}
364366

367+
this._container.bringToFront();
368+
365369
this._card.slot = this.position;
366370
if (this._container.firstElementChild && /top/u.test(this.position)) {
367371
this._container.insertBefore(this._card, this._container.firstElementChild);

packages/notification/test/notification.common.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ describe('vaadin-notification', () => {
162162
expect(container._detectIosNavbar.called).to.be.true;
163163
container._detectIosNavbar.restore();
164164
});
165+
166+
it('should bring to front on notification open ', () => {
167+
notification.opened = false;
168+
const spy = sinon.spy(container, 'bringToFront');
169+
notification.opened = true;
170+
expect(spy).to.be.calledOnce;
171+
});
165172
});
166173
});
167174

packages/overlay/src/vaadin-overlay-stack-mixin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const OverlayStackMixin = (superClass) =>
6969

7070
// Disable pointer events in other attached overlays
7171
getAttachedInstances().forEach((el) => {
72-
if (el !== this) {
72+
if (el !== this && el.$.overlay) {
7373
el.$.overlay.style.pointerEvents = 'none';
7474
}
7575
});
@@ -93,7 +93,9 @@ export const OverlayStackMixin = (superClass) =>
9393
// Skip the current instance
9494
continue;
9595
}
96-
el.$.overlay.style.removeProperty('pointer-events');
96+
if (el.$.overlay) {
97+
el.$.overlay.style.removeProperty('pointer-events');
98+
}
9799
if (!el.modeless) {
98100
// Stop after the last modal
99101
break;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { expect } from '@vaadin/chai-plugins';
2+
import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
3+
import '@vaadin/notification';
4+
import '@vaadin/popover';
5+
import '@vaadin/tooltip';
6+
7+
describe('notification and overlays', () => {
8+
describe('notification and tooltip', () => {
9+
beforeEach(async () => {
10+
const wrapper = fixtureSync(`
11+
<div>
12+
<vaadin-notification></vaadin-notification>
13+
<div id="target"></div>
14+
<vaadin-tooltip for="target" text="Tooltip" manual></vaadin-tooltip>
15+
</div>
16+
`);
17+
const notification = wrapper.querySelector('vaadin-notification');
18+
const tooltip = wrapper.querySelector('vaadin-tooltip');
19+
notification.opened = true;
20+
tooltip.opened = true;
21+
await nextRender();
22+
});
23+
24+
it('should show tooltips above notifications', () => {
25+
const notificationContainer = document.querySelector('vaadin-notification-container');
26+
const tooltipOverlay = document.querySelector('vaadin-tooltip-overlay');
27+
28+
const notificationZIndex = parseInt(getComputedStyle(notificationContainer).zIndex);
29+
const tooltipZIndex = parseInt(getComputedStyle(tooltipOverlay).zIndex);
30+
31+
expect(tooltipZIndex).to.be.above(notificationZIndex);
32+
});
33+
});
34+
35+
describe('notification and popover', () => {
36+
beforeEach(async () => {
37+
const wrapper = fixtureSync(`
38+
<div>
39+
<vaadin-notification></vaadin-notification>
40+
<div id="target"></div>
41+
<vaadin-popover for="target" manual></vaadin-popover>
42+
</div>
43+
`);
44+
const notification = wrapper.querySelector('vaadin-notification');
45+
const popover = wrapper.querySelector('vaadin-popover');
46+
popover.renderer = (root) => {
47+
root.textContent = 'Popover content';
48+
};
49+
notification.opened = true;
50+
popover.opened = true;
51+
await nextRender();
52+
});
53+
54+
it('should show popovers above notifications', () => {
55+
const notificationContainer = document.querySelector('vaadin-notification-container');
56+
const popoverOverlay = document.querySelector('vaadin-popover-overlay');
57+
58+
const notificationZIndex = parseInt(getComputedStyle(notificationContainer).zIndex);
59+
const popoverZIndex = parseInt(getComputedStyle(popoverOverlay).zIndex);
60+
61+
expect(popoverZIndex).to.be.above(notificationZIndex);
62+
});
63+
});
64+
});

test/integration/notification-tooltip.test.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)