Skip to content

Commit 7a1c3eb

Browse files
authoredAug 21, 2020
fix(ui5-popover): fix arrow horizontal position (#2129)
Fix Popover's arrow horizontal position, when horizontalPlacement is either "Left", or "Right". FIXES #2111
1 parent 023e236 commit 7a1c3eb

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed
 

‎packages/main/src/Popover.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ class Popover extends Popup {
489489

490490
this._maxContentHeight = maxContentHeight;
491491

492-
const arrowTranslateX = isVertical ? targetRect.left + targetRect.width / 2 - left - popoverSize.width / 2 : 0;
492+
const arrowXCentered = this.horizontalAlign === PopoverHorizontalAlign.Center || this.horizontalAlign === PopoverHorizontalAlign.Stretch;
493+
const arrowTranslateX = isVertical && arrowXCentered ? targetRect.left + targetRect.width / 2 - left - popoverSize.width / 2 : 0;
493494
const arrowTranslateY = !isVertical ? targetRect.top + targetRect.height / 2 - top - popoverSize.height / 2 : 0;
494495

495496
if (this._left === undefined || Math.abs(this._left - left) > 1.5) {

‎packages/main/test/pages/Popover.html

+49
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,49 @@
314314
</ui5-list>
315315
</ui5-popover>
316316

317+
<br>
318+
<br>
319+
<div id="targetOpener" style="height: 3rem; background: red;"></div>
320+
321+
<ui5-button id="btnOpenXLeft">Open Popup Left aligned</ui5-button>
322+
323+
<ui5-popover
324+
header-text="My Heading"
325+
id="popXLeft" horizontal-align="Left"
326+
style="width: 300px">
327+
<div slot="header">
328+
<ui5-button id="first-focusable">I am in the header</ui5-button>
329+
</div>
330+
<div>
331+
<ui5-button id="first-focusable">I am in the header</ui5-button>
332+
</div>
333+
<div>
334+
<ui5-button id="first-focusable">I am in the header</ui5-button>
335+
</div>
336+
</ui5-popover>
337+
338+
<div id="targetOpener2" style="height: 3rem; background: yellow;"></div>
339+
340+
<ui5-button id="btnOpenXRight">Open Popup Right aligned</ui5-button>
341+
342+
<ui5-popover
343+
header-text="My Heading"
344+
id="popXRight" horizontal-align="Right"
345+
style="width: 300px">
346+
<div slot="header">
347+
<ui5-button id="first-focusable">I am in the header</ui5-button>
348+
</div>
349+
<div>
350+
<ui5-button id="first-focusable">I am in the header</ui5-button>
351+
</div>
352+
<div>
353+
<ui5-button id="first-focusable">I am in the header</ui5-button>
354+
</div>
355+
</ui5-popover>
356+
357+
<br>
358+
<br>
359+
317360
<script>
318361
btn.addEventListener("click", function (event) {
319362
pop.openBy(btn);
@@ -380,6 +423,12 @@
380423

381424
btnQuickViewCardOpener.setAttribute("hidden", true);
382425
})
426+
btnOpenXLeft.addEventListener("click", function (event) {
427+
popXLeft.openBy(targetOpener);
428+
});
429+
btnOpenXRight.addEventListener("click", function (event) {
430+
popXRight.openBy(targetOpener2);
431+
});
383432
</script>
384433
</body>
385434

0 commit comments

Comments
 (0)
Please sign in to comment.