Skip to content

Commit

Permalink
Fix Popup positioning (#1095)
Browse files Browse the repository at this point in the history
* Fix _fitPopup of a Popup.

* rush change

* Fix tests

(cherry picked from commit 091ea17)
  • Loading branch information
GerardasB authored and mergify[bot] committed Nov 5, 2024
1 parent f167ce3 commit 6c84e88
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-react",
"comment": "Fix Popup to adjust final position based on container size instead of window size.",
"type": "none"
}
],
"packageName": "@itwin/core-react"
}
12 changes: 6 additions & 6 deletions ui/core-react/src/core-react/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -579,16 +579,16 @@ export class Popup extends React.Component<PopupProps, PopupState> {
return fittedPoint;
}

// const popupRect = this._popup.getBoundingClientRect();
const { popupWidth, popupHeight } = this._getPopupDimensions();
const { innerWidth, innerHeight } = window;
const container = this.getContainer();
const containerBounds = container.getBoundingClientRect();

if (fittedPoint.y + popupHeight > innerHeight) {
fittedPoint.y = innerHeight - popupHeight;
if (fittedPoint.y + popupHeight > containerBounds.height) {
fittedPoint.y = containerBounds.height - popupHeight;
}

if (fittedPoint.x + popupWidth > innerWidth) {
fittedPoint.x = innerWidth - popupWidth;
if (fittedPoint.x + popupWidth > containerBounds.width) {
fittedPoint.x = containerBounds.width - popupWidth;
}

if (fittedPoint.y < 0) {
Expand Down
3 changes: 3 additions & 0 deletions ui/core-react/src/test/popup/Popup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ describe("<Popup />", () => {
vi.spyOn(targetElement, "getBoundingClientRect").mockReturnValue(
DOMRect.fromRect({ x: 100, y: 100, height: 50, width: 50 })
);
vi.spyOn(document.body, "getBoundingClientRect").mockReturnValue(
DOMRect.fromRect({ x: 0, y: 0, width: 1000, height: 1000 })
);
});

afterEach(() => {
Expand Down

0 comments on commit 6c84e88

Please sign in to comment.