Skip to content

Commit

Permalink
fix: margin position issue
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Mar 19, 2023
1 parent 1bb71d1 commit 14aaf9b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/selectmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ function reposition(reference, popover) {

style.removeProperty('height');
style.top = 'auto';
style.bottom = 'auto';

const container = { top: 0, height: window.innerHeight };
const refBox = reference.getBoundingClientRect();
Expand All @@ -405,9 +406,9 @@ function reposition(reference, popover) {

style.top = `${refBox.bottom}px`;

let popBox = popover.getBoundingClientRect();
let popBox = popover.getBoundingClientRect();

const bottomOverflow = popBox.bottom - container.height;

if (bottomOverflow > 0) {

let newHeight = popBox.height - bottomOverflow;
Expand All @@ -417,7 +418,8 @@ function reposition(reference, popover) {

} else {

style.top = `${refBox.top - popBox.height}px`;
style.top = 'auto';
style.bottom = `${container.height - refBox.top}px`;

popBox = popover.getBoundingClientRect();

Expand All @@ -426,6 +428,7 @@ function reposition(reference, popover) {

if (topOverflow > 0) {
style.top = container.top;
style.bottom = 'auto';
style.height = `${newHeight}px`;
}
}
Expand All @@ -441,11 +444,13 @@ function reposition(reference, popover) {
function getOrInsertCSSRule(styleParent, selectorText) {
let style;
for (style of styleParent.querySelectorAll('style')) {

// Catch this error. e.g. browser extension adds style tags.
// Uncaught DOMException: CSSStyleSheet.cssRules getter:
// Not allowed to access cross-origin stylesheet
let cssRules;
try { cssRules = style.sheet?.cssRules; } catch { continue; }

for (let rule of cssRules ?? [])
if (rule.selectorText === selectorText) return rule;
}
Expand Down

1 comment on commit 14aaf9b

@vercel
Copy link

@vercel vercel bot commented on 14aaf9b Mar 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

selectmenu-polyfill – ./

selectmenu-polyfill-luwes.vercel.app
selectmenu-polyfill.vercel.app
selectmenu-polyfill-git-main-luwes.vercel.app

Please sign in to comment.