Skip to content

Commit 3b2d6de

Browse files
authored
feat(ui5-popover): implement hide-block-layer property (#2413)
1 parent 3f66c06 commit 3b2d6de

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

packages/main/src/Dialog.js

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ class Dialog extends Popup {
187187
return true;
188188
}
189189

190+
get shouldHideBackdrop() { // Required by Popup.js
191+
return false;
192+
}
193+
190194
get _ariaLabelledBy() { // Required by Popup.js
191195
return this.ariaLabel ? undefined : "ui5-popup-header";
192196
}

packages/main/src/Popover.js

+15
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ const metadata = {
106106
type: Boolean,
107107
},
108108

109+
/**
110+
* Defines whether the block layer will be shown if modal property is set to true.
111+
* @type {boolean}
112+
* @defaultvalue false
113+
* @public
114+
* @since 1.0.0-rc.10
115+
*/
116+
hideBackdrop: {
117+
type: Boolean,
118+
},
119+
109120
/**
110121
* Determines whether the <code>ui5-popover</code> arrow is hidden.
111122
*
@@ -620,6 +631,10 @@ class Popover extends Popup {
620631
return this.modal;
621632
}
622633

634+
get shouldHideBackdrop() { // Required by Popup.js
635+
return this.hideBackdrop;
636+
}
637+
623638
get _ariaLabelledBy() { // Required by Popup.js
624639
return this.ariaLabel ? undefined : "ui5-popup-header";
625640
}

packages/main/src/Popup.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const metadata = {
6767
* Defines the aria-label attribute for the popup
6868
*
6969
* @type {String}
70-
* @defaultvalue: ""
70+
* @defaultvalue ""
7171
* @private
7272
* @since 1.0.0-rc.8
7373
*/
@@ -313,7 +313,7 @@ class Popup extends UI5Element {
313313
return;
314314
}
315315

316-
if (this.isModal) {
316+
if (this.isModal && !this.shouldHideBackdrop) {
317317
// create static area item ref for block layer
318318
this.getStaticAreaItemDomRef();
319319
this._blockLayerHidden = false;
@@ -430,6 +430,15 @@ class Popup extends UI5Element {
430430
*/
431431
get isModal() {} // eslint-disable-line
432432

433+
/**
434+
* Implement this getter with relevant logic in order to hide the block layer (f.e. based on a public property)
435+
*
436+
* @protected
437+
* @abstract
438+
* @returns {boolean}
439+
*/
440+
get shouldHideBackdrop() {} // eslint-disable-line
441+
433442
/**
434443
* Return the ID of an element in the shadow DOM that is going to label this popup
435444
*

packages/main/test/pages/Popover.html

+22
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@
171171
</div>
172172
</ui5-popover>
173173

174+
<ui5-button id="btnPopModalNoLayer">Opens modal popover with no block layer!</ui5-button>
175+
176+
<ui5-popover id="modalPopoverNoLayer" modal header-text="Modal popover" hide-backdrop>
177+
<ui5-list>
178+
<ui5-li>Hello</ui5-li>
179+
<ui5-li>Again</ui5-li>
180+
<ui5-li>Wooooooooooooooooooooooooooooorld</ui5-li>
181+
</ui5-list>
182+
183+
<div slot="footer">
184+
<ui5-button id="modalPopoverNoLayerClose">Close</ui5-button>
185+
</div>
186+
</ui5-popover>
187+
174188
<ui5-button id="btnPopFocus">Opens popover with initial focus!</ui5-button>
175189

176190
<ui5-popover id="popFocus" initial-focus="focusMe" header-text="Popover header">
@@ -374,6 +388,14 @@
374388
modalPopover.openBy(btnPopModal);
375389
});
376390

391+
btnPopModalNoLayer.addEventListener("click", function() {
392+
modalPopoverNoLayer.openBy(btnPopModalNoLayer);
393+
});
394+
395+
modalPopoverNoLayerClose.addEventListener("click", function() {
396+
modalPopoverNoLayer.close();
397+
});
398+
377399
modalPopoverClose.addEventListener("click", function (event) {
378400
modalPopover.close();
379401
});

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

+26
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,32 @@ describe("Popover general interaction", () => {
137137
assert.ok(!popover.isDisplayedInViewport(), "Popover is closed.");
138138
});
139139

140+
it("tests modal popover with no block layer", () => {
141+
const btnOpenPopover = $("#btnPopModalNoLayer");
142+
const popover = $("#modalPopoverNoLayer");
143+
const popoverId = popover.getProperty("_id");
144+
145+
btnOpenPopover.click();
146+
assert.ok(popover.getProperty("opened"), "Popover is opened.");
147+
148+
const blockLayerIsCreated = browser.execute( (popoverId) => {
149+
const staticAreaItems = document.querySelectorAll("ui5-static-area-item");
150+
let result = false;
151+
152+
staticAreaItems.forEach(item => {
153+
if (item.shadowRoot.querySelector(".ui5-block-layer") && item.classList.contains(popoverId)) {
154+
result = true;
155+
}
156+
});
157+
158+
return result
159+
}, popoverId);
160+
161+
assert.notOk(blockLayerIsCreated, "Block layer is not created.");
162+
163+
browser.keys("Escape");
164+
});
165+
140166
it("tests initial focus", () => {
141167
const focusedButton = $("#focusMe");
142168
const btnOpenPopover = $("#btnPopFocus");

0 commit comments

Comments
 (0)