Skip to content

Commit 0199847

Browse files
authored
refactor: make it possible to customize overlay content root (#9744)
1 parent aed5aaf commit 0199847

File tree

4 files changed

+310
-136
lines changed

4 files changed

+310
-136
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ export const OverlayFocusMixin = (superClass) =>
5353
this.__focusRestorationController = new FocusRestorationController();
5454
}
5555

56+
/**
57+
* Override to specify another element used as a content root,
58+
* e.g. slotted into the overlay, rather than overlay itself.
59+
* @protected
60+
*/
61+
get _contentRoot() {
62+
return this;
63+
}
64+
5665
/** @protected */
5766
ready() {
5867
super.ready();
@@ -127,15 +136,15 @@ export const OverlayFocusMixin = (superClass) =>
127136
* @protected
128137
*/
129138
_deepContains(node) {
130-
if (this.contains(node)) {
139+
if (this._contentRoot.contains(node)) {
131140
return true;
132141
}
133142
let n = node;
134143
const doc = node.ownerDocument;
135-
// Walk from node to `this` or `document`
136-
while (n && n !== doc && n !== this) {
144+
// Walk from node to content root or `document`
145+
while (n && n !== doc && n !== this._contentRoot) {
137146
n = n.parentNode || n.host;
138147
}
139-
return n === this;
148+
return n === this._contentRoot;
140149
}
141150
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export const OverlayMixin = (superClass) =>
163163
*/
164164
requestContentUpdate() {
165165
if (this.renderer) {
166-
this.renderer.call(this.owner, this, this.owner, this.model);
166+
this.renderer.call(this.owner, this._contentRoot, this.owner, this.model);
167167
}
168168
}
169169

@@ -256,11 +256,11 @@ export const OverlayMixin = (superClass) =>
256256
this._oldOpened = opened;
257257

258258
if (rendererChanged && hasOldRenderer) {
259-
this.innerHTML = '';
259+
this._contentRoot.innerHTML = '';
260260
// Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
261261
// When clearing the rendered content, this part needs to be manually disposed of.
262262
// Otherwise, using a Lit-based renderer on the same node will throw an exception or render nothing afterward.
263-
delete this._$litPart$;
263+
delete this._contentRoot._$litPart$;
264264
}
265265

266266
if (opened && renderer && (rendererChanged || openedChanged || ownerOrModelChanged)) {

0 commit comments

Comments
 (0)