Skip to content

Commit

Permalink
resolve #6206 A popup appears incorrectly when using the search option
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaLarina committed Jul 14, 2023
1 parent 29f4fd9 commit 74b863e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/popup-dropdown-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ export class PopupDropdownViewModel extends PopupBaseViewModel {
);

if (!!window) {
const newVerticalDimensions = PopupUtils.updateVerticalDimensions(
const newVerticalDimensions = PopupUtils.getCorrectedVerticalDimensions(
pos.top,
height,
window.innerHeight
);
if (!!newVerticalDimensions) {
if (!!newVerticalDimensions.height) {
this.height = newVerticalDimensions.height + "px";
pos.top = newVerticalDimensions.top;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export class PopupUtils {
return { left: Math.round(currentLeft), top: Math.round(currentTop) };
}

public static updateVerticalDimensions(
public static getCorrectedVerticalDimensions(
top: number,
height: number,
windowHeight: number
) {
let result;
let result = { height: height, top: top };
if (top < 0) {
result = { height: height + top, top: 0 };
} else if (height + top > windowHeight) {
Expand Down
37 changes: 17 additions & 20 deletions tests/components/popuptests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1006,26 +1006,23 @@ QUnit.test("Check calculatePosition with window size method", (assert) => {
);
});

QUnit.test(
"Check updateVerticalDimensions if both directions do not fit",
(assert) => {
let newVerticalDimensions = PopupUtils.updateVerticalDimensions(
-20,
200,
300
);
assert.equal(newVerticalDimensions.height, 180);
assert.equal(newVerticalDimensions.top, 0);

newVerticalDimensions = PopupUtils.updateVerticalDimensions(150, 200, 300);
assert.equal(newVerticalDimensions.height, 150 - PopupUtils.bottomIndent);
assert.equal(newVerticalDimensions.top, 150);

newVerticalDimensions = PopupUtils.updateVerticalDimensions(150, 450, 300);
assert.equal(newVerticalDimensions.height, 150 - PopupUtils.bottomIndent);
assert.equal(newVerticalDimensions.top, 150);
}
);
QUnit.test("Check getCorrectedVerticalDimensions if both directions do not fit", (assert) => {
let newVerticalDimensions = PopupUtils.getCorrectedVerticalDimensions(-20, 200, 300);
assert.equal(newVerticalDimensions.height, 180);
assert.equal(newVerticalDimensions.top, 0);

newVerticalDimensions = PopupUtils.getCorrectedVerticalDimensions(150, 200, 300);
assert.equal(newVerticalDimensions.height, 150 - PopupUtils.bottomIndent);
assert.equal(newVerticalDimensions.top, 150);

newVerticalDimensions = PopupUtils.getCorrectedVerticalDimensions(150, 450, 300);
assert.equal(newVerticalDimensions.height, 150 - PopupUtils.bottomIndent);
assert.equal(newVerticalDimensions.top, 150);

newVerticalDimensions = PopupUtils.getCorrectedVerticalDimensions(10, 200, 300);
assert.equal(newVerticalDimensions.height, 200);
assert.equal(newVerticalDimensions.top, 10);
});

QUnit.test("Check updateHorizontalDimensions", (assert) => {
let newHorizontalDimensions = PopupUtils.updateHorizontalDimensions(-20, 200, 300, "center");
Expand Down

0 comments on commit 74b863e

Please sign in to comment.