Skip to content

Commit 6f82e42

Browse files
authored
fix(ui5-popup): fix(ui5-popup): hide block layer if popup is closed (#2799)
The block layer is created when #getStaticAreaItemDomRef is called, but the attribute "hidden" is not set at that time. Now it's set on onEnterDOM hook, unless the popup is already opened. Fixes: #2696
1 parent e842f23 commit 6f82e42

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

packages/main/src/Dialog.js

+4
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,15 @@ class Dialog extends Popup {
223223
}
224224

225225
onEnterDOM() {
226+
super.onEnterDOM();
227+
226228
ResizeHandler.register(this, this._screenResizeHandler);
227229
ResizeHandler.register(document.body, this._screenResizeHandler);
228230
}
229231

230232
onExitDOM() {
233+
super.onExitDOM();
234+
231235
ResizeHandler.deregister(this, this._screenResizeHandler);
232236
ResizeHandler.deregister(document.body, this._screenResizeHandler);
233237
}

packages/main/src/Popup.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const metadata = {
5656
},
5757

5858
/**
59-
* Indicates if the elements is open
59+
* Indicates if the element is open
6060
* @private
6161
* @type {boolean}
6262
* @defaultvalue false
@@ -207,6 +207,19 @@ class Popup extends UI5Element {
207207
return staticAreaStyles;
208208
}
209209

210+
onEnterDOM() {
211+
if (!this.isOpen()) {
212+
this._blockLayerHidden = true;
213+
}
214+
}
215+
216+
onExitDOM() {
217+
if (this.isOpen()) {
218+
Popup.unblockBodyScrolling();
219+
this._removeOpenedPopup();
220+
}
221+
}
222+
210223
get _displayProp() {
211224
return "block";
212225
}
@@ -432,13 +445,6 @@ class Popup extends UI5Element {
432445
this.style.display = "none";
433446
}
434447

435-
onExitDOM() {
436-
if (this.isOpen()) {
437-
Popup.unblockBodyScrolling();
438-
this._removeOpenedPopup();
439-
}
440-
}
441-
442448
/**
443449
* Implement this getter with relevant logic regarding the modality of the popup (e.g. based on a public property)
444450
*

packages/main/test/specs/Dialog.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ describe("Dialog general interaction", () => {
127127

128128
closeButton.click();
129129
});
130+
131+
it("test dialog overlay when dialog isn't open", () => {
132+
const isBlockLayerHidden = browser.executeAsync(async (done) => {
133+
const dialog = document.getElementById("dialog");
134+
const staticAreaItemDomRef = await dialog.getStaticAreaItemDomRef();
135+
136+
done(staticAreaItemDomRef.querySelector(".ui5-block-layer").hasAttribute("hidden"));
137+
});
138+
139+
assert.ok(isBlockLayerHidden, "the block layer is hidden");
140+
});
130141
});
131142

132143

0 commit comments

Comments
 (0)