Skip to content

Commit 16e45ec

Browse files
fix(ui5-popover): correct position of the arrow when the Popover is below the target
In case when the target is button with small width the arrow should be centered to the button. Fixes #7152
1 parent 03f28b9 commit 16e45ec

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

packages/main/src/Popover.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,11 @@ class Popover extends Popup {
668668
safeRangeForArrowX,
669669
);
670670

671+
if (isVertical) {
672+
// if the target is with small width - only icon button for example
673+
const arrowTranslateXMinimum = -(popoverSize.width / 2 - (targetRect.width / 2 + targetRect.left) + ARROW_SIZE);
674+
arrowTranslateX = (arrowTranslateX < arrowTranslateXMinimum) ? arrowTranslateX : arrowTranslateXMinimum;
675+
}
671676
return {
672677
x: Math.round(arrowTranslateX),
673678
y: Math.round(arrowTranslateY),

packages/main/src/themes/Popover.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
:host([actual-placement-type="Bottom"]) .ui5-popover-arrow {
2121
left: calc(50% - 0.5625rem);
2222
top: -0.5rem;
23-
height: 0.5625rem;
23+
height: 0.5rem;
2424
}
2525

2626
:host([actual-placement-type="Bottom"]) .ui5-popover-arrow:after {
@@ -74,7 +74,7 @@
7474
.ui5-popover-arrow {
7575
pointer-events: none;
7676
display: block;
77-
width: 1rem;
77+
width: calc(1rem + 2px);
7878
height: 1rem;
7979
position: absolute;
8080
overflow: hidden;

packages/main/test/pages/Popover.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@
343343
<br>
344344
<br>
345345

346+
<div class="popover12auto-left">
347+
<ui5-button id="btnOpenDynamicLeft" icon="overflow"></ui5-button>
348+
</div>
349+
346350
<div class="popover12auto">
347351
<ui5-button id="btnOpenDynamic" icon="overflow"></ui5-button>
348352
</div>
@@ -558,6 +562,20 @@ <h2>Horizontal Align</h2>
558562
popNoFocusableContent.showAt(event.target);
559563
});
560564

565+
btnOpenDynamicLeft.addEventListener("click", function () {
566+
var popoverLeft = document.createElement("ui5-popover"),
567+
buttonLeft = document.createElement("ui5-button");
568+
569+
buttonLeft.textContent = "Focusable element";
570+
popoverLeft.appendChild(buttonLeft);
571+
popoverLeft.setAttribute("id", "dynamic-popover-left");
572+
popoverLeft.setAttribute("placement-type", "Bottom");
573+
574+
document.body.appendChild(popoverLeft);
575+
576+
popoverLeft.showAt(btnOpenDynamicLeft);
577+
});
578+
561579
btnOpenDynamic.addEventListener("click", function () {
562580
var popover = document.createElement("ui5-popover"),
563581
button = document.createElement("ui5-button");

0 commit comments

Comments
 (0)