Skip to content

Commit

Permalink
fix(ui5-popover): fix arrow horizontal position (#2129)
Browse files Browse the repository at this point in the history
Fix Popover's arrow horizontal position, when horizontalPlacement is either "Left", or "Right".

FIXES #2111
  • Loading branch information
ilhan007 committed Oct 17, 2020
1 parent 7d13037 commit 6a8dbe2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/main/src/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ class Popover extends Popup {

this._maxContentHeight = maxContentHeight;

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

if (this._left === undefined || Math.abs(this._left - left) > 1.5) {
Expand Down
49 changes: 49 additions & 0 deletions packages/main/test/pages/Popover.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,49 @@
</ui5-list>
</ui5-popover>

<br>
<br>
<div id="targetOpener" style="height: 3rem; background: red;"></div>

<ui5-button id="btnOpenXLeft">Open Popup Left aligned</ui5-button>

<ui5-popover
header-text="My Heading"
id="popXLeft" horizontal-align="Left"
style="width: 300px">
<div slot="header">
<ui5-button id="first-focusable">I am in the header</ui5-button>
</div>
<div>
<ui5-button id="first-focusable">I am in the header</ui5-button>
</div>
<div>
<ui5-button id="first-focusable">I am in the header</ui5-button>
</div>
</ui5-popover>

<div id="targetOpener2" style="height: 3rem; background: yellow;"></div>

<ui5-button id="btnOpenXRight">Open Popup Right aligned</ui5-button>

<ui5-popover
header-text="My Heading"
id="popXRight" horizontal-align="Right"
style="width: 300px">
<div slot="header">
<ui5-button id="first-focusable">I am in the header</ui5-button>
</div>
<div>
<ui5-button id="first-focusable">I am in the header</ui5-button>
</div>
<div>
<ui5-button id="first-focusable">I am in the header</ui5-button>
</div>
</ui5-popover>

<br>
<br>

<script>
btn.addEventListener("click", function (event) {
pop.openBy(btn);
Expand Down Expand Up @@ -380,6 +423,12 @@

btnQuickViewCardOpener.setAttribute("hidden", true);
})
btnOpenXLeft.addEventListener("click", function (event) {
popXLeft.openBy(targetOpener);
});
btnOpenXRight.addEventListener("click", function (event) {
popXRight.openBy(targetOpener2);
});
</script>
</body>

Expand Down

0 comments on commit 6a8dbe2

Please sign in to comment.