Skip to content

Commit 6671793

Browse files
authored
fix(ui5-popover): restrict max content height when overflowing the screen (#908)
FIXES: #853
1 parent 58e2170 commit 6671793

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

packages/main/src/Popover.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<span class="first-fe" tabindex="0" @focusin={{forwardToLast}}></span>
1414

15-
<div class="ui5-popover-content">
15+
<div class="ui5-popover-content" style={{styles.content}}>
1616
<slot></slot>
1717
</div>
1818

packages/main/src/Popover.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ const metadata = {
151151
* @private
152152
*/
153153
opened: { type: Boolean },
154+
155+
_maxContentHeight: { type: Integer },
154156
},
155157
slots: {
156158
/**
@@ -545,8 +547,12 @@ class Popover extends UI5Element {
545547

546548
let maxContentHeight = Math.round(maxHeight);
547549

548-
if (this.hasHeader) {
549-
const headerDomRef = this.getPopupDomRef().querySelector(".ui5-popup-header");
550+
const hasHeader = this.header.length || this.headerText;
551+
552+
if (hasHeader) {
553+
const headerDomRef = this.shadowRoot.querySelector(".ui5-popover-header-root")
554+
|| this.shadowRoot.querySelector(".ui5-popup-header-text");
555+
550556
if (headerDomRef) {
551557
maxContentHeight = Math.round(maxHeight - headerDomRef.offsetHeight);
552558
}
@@ -651,6 +657,9 @@ class Popover extends UI5Element {
651657

652658
get styles() {
653659
return {
660+
content: {
661+
"max-height": `${this._maxContentHeight}px`,
662+
},
654663
arrow: {
655664
transform: `translate(${this.arrowTranslateX}px, ${this.arrowTranslateY}px)`,
656665
},

packages/main/src/themes/Popover.css

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137

138138
/* Consider how to make this top level */
139139
padding: var(--_ui5_popover_content_padding);
140+
box-sizing: border-box;
140141
}
141142

142143
:host([header-text]) .ui5-popup-header-text {

packages/main/test/pages/Popover.html

+24
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@
136136
<br>
137137
<br>
138138

139+
<ui5-select id="many-items"></ui5-select>
140+
141+
<br>
142+
<br>
143+
144+
<ui5-button id="big-popover-button">
145+
Open Big Popover
146+
</ui5-button>
147+
148+
<ui5-popover placement-type="Bottom" id="big-popover" header-text="hello world">
149+
<ui5-list id="bigList"></ui5-list>
150+
</ui5-popover>
139151

140152
<script>
141153

@@ -151,6 +163,18 @@
151163
bigDangerPop.openBy(bigDanger);
152164
});
153165

166+
document.getElementById("many-items").innerHTML = [].map.call("Ullamco ea ad fugiat enim elit dolore ullamco ad magna excepteur cupidatat.", function (item, index) {
167+
return "<ui5-option>" + item + "</ui5-option>";
168+
}).join("");
169+
170+
document.getElementById("bigList").innerHTML = [].map.call("Ullamco ea ad fugiat enim elit dolore ullamco ad magna excepteur cupidatat.", function (item, index) {
171+
return "<ui5-li>" + item + "</ui5-li>";
172+
}).join("");
173+
174+
document.getElementById("big-popover-button").addEventListener("click", function (event) {
175+
document.getElementById("big-popover").openBy(event.target);
176+
});
177+
154178
</script>
155179
</body>
156180

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

+33
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,37 @@ describe("Popover general interaction", () => {
2828
btnInPopover.click();
2929
assert.ok(popover.isDisplayedInViewport(), "Popover remains opened.");
3030
});
31+
32+
it("tests if overflown content can be reached by scrolling", () => {
33+
const manyItemsSelect = $("#many-items");
34+
const items = manyItemsSelect.shadow$$("ui5-li");
35+
36+
manyItemsSelect.click();
37+
38+
const lastListItem = items[items.length - 1];
39+
40+
assert.strictEqual(lastListItem.isDisplayedInViewport(), false, "Last item is not displayed after openining");
41+
42+
lastListItem.scrollIntoView();
43+
44+
assert.strictEqual(lastListItem.isDisplayedInViewport(), true, "Last item is displayed after scrolling");
45+
46+
manyItemsSelect.click();
47+
});
48+
49+
it("tests if overflown content can be reached by scrolling (with header and arrow)", () => {
50+
const bigPopover = $("#big-popover");
51+
const items = bigPopover.$$("ui5-li");
52+
const openBigPopoverButton = $("#big-popover-button")
53+
54+
openBigPopoverButton.click();
55+
56+
const lastListItem = items[items.length - 1];
57+
58+
assert.strictEqual(lastListItem.isDisplayedInViewport(), false, "Last item is not displayed after openining");
59+
60+
lastListItem.scrollIntoView();
61+
62+
assert.strictEqual(lastListItem.isDisplayedInViewport(), true, "Last item is displayed after scrolling");
63+
});
3164
});

0 commit comments

Comments
 (0)