Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui5-popover): implement hide-block-layer property #2413

Merged
merged 5 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/main/src/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ class Dialog extends Popup {
return true;
}

get shouldHideBlockLayer() { // Required by Popup.js
return false;
}

get _ariaLabelledBy() { // Required by Popup.js
return this.ariaLabel ? undefined : "ui5-popup-header";
}
Expand Down
15 changes: 15 additions & 0 deletions packages/main/src/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ const metadata = {
type: Boolean,
},

/**
* Defines whether the block layer will be shown if modal property is set to true.
* @type {boolean}
* @defaultvalue false
* @public
* @since 1.0.0-rc.10
*/
hideBlockLayer: {
type: Boolean,
},

/**
* Determines whether the <code>ui5-popover</code> arrow is hidden.
*
Expand Down Expand Up @@ -620,6 +631,10 @@ class Popover extends Popup {
return this.modal;
}

get shouldHideBlockLayer() { // Required by Popup.js
return this.hideBlockLayer;
}

get _ariaLabelledBy() { // Required by Popup.js
return this.ariaLabel ? undefined : "ui5-popup-header";
}
Expand Down
13 changes: 11 additions & 2 deletions packages/main/src/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const metadata = {
* Defines the aria-label attribute for the popup
*
* @type {String}
* @defaultvalue: ""
* @defaultvalue ""
* @private
* @since 1.0.0-rc.8
*/
Expand Down Expand Up @@ -308,7 +308,7 @@ class Popup extends UI5Element {
return;
}

if (this.isModal) {
if (this.isModal && !this.shouldHideBlockLayer) {
// create static area item ref for block layer
this.getStaticAreaItemDomRef();
this._blockLayerHidden = false;
Expand Down Expand Up @@ -425,6 +425,15 @@ class Popup extends UI5Element {
*/
get isModal() {} // eslint-disable-line

/**
* Implement this getter with relevant logic in order to hide the block layer (f.e. based on a public property)
*
* @protected
* @abstract
* @returns {boolean}
*/
get shouldHideBlockLayer() {} // eslint-disable-line

/**
* Return the ID of an element in the shadow DOM that is going to label this popup
*
Expand Down
22 changes: 22 additions & 0 deletions packages/main/test/pages/Popover.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@
</div>
</ui5-popover>

<ui5-button id="btnPopModalNoLayer">Opens modal popover with no block layer!</ui5-button>

<ui5-popover id="modalPopoverNoLayer" modal header-text="Modal popover" hide-block-layer>
<ui5-list>
<ui5-li>Hello</ui5-li>
<ui5-li>Again</ui5-li>
<ui5-li>Wooooooooooooooooooooooooooooorld</ui5-li>
</ui5-list>

<div slot="footer">
<ui5-button id="modalPopoverNoLayerClose">Close</ui5-button>
</div>
</ui5-popover>

<ui5-button id="btnPopFocus">Opens popover with initial focus!</ui5-button>

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

btnPopModalNoLayer.addEventListener("click", function() {
modalPopoverNoLayer.openBy(btnPopModalNoLayer);
});

modalPopoverNoLayerClose.addEventListener("click", function() {
modalPopoverNoLayer.close();
});

modalPopoverClose.addEventListener("click", function (event) {
modalPopover.close();
});
Expand Down
26 changes: 26 additions & 0 deletions packages/main/test/specs/Popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,32 @@ describe("Popover general interaction", () => {
assert.ok(!popover.isDisplayedInViewport(), "Popover is closed.");
});

it("tests modal popover with no block layer", () => {
const btnOpenPopover = $("#btnPopModalNoLayer");
const popover = $("#modalPopoverNoLayer");
const popoverId = popover.getProperty("_id");

btnOpenPopover.click();
assert.ok(popover.getProperty("opened"), "Popover is opened.");

const blockLayerIsCreated = browser.execute( (popoverId) => {
const staticAreaItems = document.querySelectorAll("ui5-static-area-item");
let result = false;

staticAreaItems.forEach(item => {
if (item.shadowRoot.querySelector(".ui5-block-layer") && item.classList.contains(popoverId)) {
result = true;
}
});

return result
}, popoverId);

assert.notOk(blockLayerIsCreated, "Block layer is not created.");

browser.keys("Escape");
});

it("tests initial focus", () => {
const focusedButton = $("#focusMe");
const btnOpenPopover = $("#btnPopFocus");
Expand Down