Skip to content

Commit

Permalink
fix(popup): subtract margins when calculating max popup size
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyzerner committed Oct 12, 2023
1 parent f7b5450 commit f842b6d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,23 @@ export default class PopupElement extends HTMLElement {
shift(),
flip(),
size({
apply: ({ availableWidth, availableHeight }) => {
apply: ({
availableWidth,
availableHeight,
placement,
}) => {
this.content.dataset.placement = placement;

Object.assign(this.content.style, {
maxWidth: '',
maxHeight: '',
});

const computed = getComputedStyle(this.content);

// TODO: subtract margins
availableWidth -=
parseInt(computed.marginLeft) +
parseInt(computed.marginRight);

if (
computed.maxWidth === 'none' ||
Expand All @@ -183,6 +191,10 @@ export default class PopupElement extends HTMLElement {
this.content.style.maxWidth = `${availableWidth}px`;
}

availableHeight -=
parseInt(computed.marginTop) +
parseInt(computed.marginBottom);

if (
computed.maxHeight === 'none' ||
availableHeight <
Expand All @@ -193,12 +205,11 @@ export default class PopupElement extends HTMLElement {
},
}),
],
}).then(({ x, y, placement }) => {
}).then(({ x, y }) => {
Object.assign(this.content.style, {
left: `${x}px`,
top: `${y}px`,
});
this.content.dataset.placement = placement;
});
},
{ ancestorScroll: false }
Expand Down

0 comments on commit f842b6d

Please sign in to comment.