Skip to content

Commit 9f36b3e

Browse files
authored
Merge pull request #2053 from IgniteUI/dkamburov/fix-1918-19.2
Fix for 1918 - Try to fit the popover into containment area if possible
2 parents a9a945a + 2d641cc commit 9f36b3e

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

src/js/modules/infragistics.ui.popover.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@
10831083
},
10841084
_rightPosition: function (trg) {
10851085
var right = $.ig.util.offset(trg).left + trg.outerWidth(),
1086-
parentRight = $.ig.util.offset(trg.offsetParent()).right + trg.outerWidth();
1086+
parentRight = $.ig.util.offset(trg.offsetParent()).left + trg.offsetParent().outerWidth();
10871087
if (right > parentRight) {
10881088
right = parentRight;
10891089
}
@@ -1103,7 +1103,7 @@
11031103
leftBoundary = win.scrollLeft();
11041104
topBoundary = win.scrollTop();
11051105
$containment = this.options.containment;
1106-
if (this.options.containment) {
1106+
if ($containment) {
11071107
if (leftBoundary < $.ig.util.offset($containment).left) {
11081108
leftBoundary = $.ig.util.offset($containment).left;
11091109
}
@@ -1130,6 +1130,12 @@
11301130
if (top < topBoundary) {
11311131
top = topBoundary;
11321132
}
1133+
/* Try to fit the popover within the contaiment if poosible */
1134+
if (this.oDir === "right" &&
1135+
$containment &&
1136+
left + trg.outerWidth() > rightBoundary) {
1137+
left = rightBoundary - trg.outerWidth();
1138+
}
11331139
}
11341140
/*D.K. 7 Apr 2015 Fix for bug #190611: When direction is right and mouse over the last column popover is shown to the cell on the left
11351141
When the direction is right, don't recalculate 'left', show it even if it is in the invisible area */

tests/unit/popover/specific/specific-test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,48 @@ QUnit.test("Test popover when initialized on multiple items without ID on the pa
4646
throw er;
4747
});
4848

49+
});
50+
51+
//bug https://github.com/IgniteUI/ignite-ui/issues/1918
52+
QUnit.test("Test popover when containment, direction and position are specified", function (assert) {
53+
var divElement = `<div id="containment">
54+
<input id="right" placeholder="Focus me to show popover to the right" style="width:250px";/>
55+
</div>`;
56+
var self = this, done = assert.async(), popover;
57+
this.testUtil.appendToFixture(divElement);
58+
$('#containment').css({"background-color": "bisque",
59+
width: "500px",
60+
height: "400px",
61+
margin: "50px 0 0 100px",
62+
display: "flex",
63+
"flex-flow": "column",
64+
"align-items": "center",
65+
"justify-content": "center"});
66+
$("#right").igPopover({
67+
containment: $('#containment'),
68+
direction: "right",
69+
position: "end",
70+
height: 100,
71+
width: 300,
72+
showOn: 'focus',
73+
closeOnBlur: true
74+
});
75+
76+
this.testUtil.wait(200).then(function () {
77+
$("#right").trigger("focus");
78+
self.testUtil.wait(100).then(function () {
79+
done();
80+
popover = $('#right').data().igPopover.popover;
81+
var containmentRect = $('#containment')[0].getBoundingClientRect();
82+
assert.ok(popover.length > 0 && popover.closest(document.documentElement).length > 0 && popover.is(":visible"), "Popover element should exist and should be visible");
83+
assert.ok(popover.position().left > containmentRect.left, "Popover is positioned correctly");
84+
assert.ok(popover.position().left + popover.outherWidth() < containmentRect.right, "Popover is positioned correctly");
85+
assert.ok(popover.position().top > containmentRect.top, "Popover is positioned correctly");
86+
assert.ok(popover.position().top + popover.outherHeight() < containmentRect.bottom, "Popover is positioned correctly");
87+
});
88+
}).catch(function (er) {
89+
assert.pushResult({ result: false, message: er.message });
90+
done();
91+
throw er;
92+
});
4993
});

0 commit comments

Comments
 (0)