Skip to content

Commit

Permalink
Merge pull request #1869 from Kajabi/fix/sentry-error-dropdown-positi…
Browse files Browse the repository at this point in the history
…on-function

Fix sentry errors for null related to Sage Dropdown
  • Loading branch information
monicawheeler authored Mar 12, 2024
2 parents 18e83f6 + 10a9683 commit 152d794
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/sage-system/lib/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,23 @@ Sage.dropdown = (function () {
return height - borderBottomWidth - borderTopWidth - paddingTop - paddingBottom;
}

function positionElement(el) {
function positionElement(dropdownElement) {
// Guard clause to check if wrapperRef.current is null
if (!dropdownElement) return;

let directionX = null;
let directionY = null;

// Elements
const button = el;
const panel = el.lastElementChild;
const button = dropdownElement;
const panel = dropdownElement.lastElementChild;
const win = panel.ownerDocument.defaultView;
const docEl = window.document.documentElement;

panel.style.top = ''; // resets the style
panel.style.left = ''; // resets the style
panel.style.right = ''; // resets the style

// Dimensions
const buttonDimensions = button.getBoundingClientRect();
const panelDimensions = panel.getBoundingClientRect();
Expand All @@ -211,14 +214,14 @@ Sage.dropdown = (function () {
top: (buttonDimensions.height / 2) + panelDimensions.height,
left: (buttonDimensions.width / 2) + panelDimensions.width,
};

const viewport = {
top: docEl.scrollTop,
bottom: window.pageYOffset + docEl.clientHeight,
left: docEl.scrollLeft,
right: window.pageXOffset + docEl.clientWidth,
};

const offset = {
top: panelDimensions.top + win.pageYOffset,
left: panelDimensions.left + win.pageXOffset,
Expand Down Expand Up @@ -253,7 +256,7 @@ Sage.dropdown = (function () {
} else if (!enoughSpaceLeft && enoughSpaceRight) {
directionX = 'right';
}

if (directionX === 'left') {
panel.style.left = 'inherit';
panel.style.right = 0;
Expand All @@ -262,7 +265,7 @@ Sage.dropdown = (function () {
panel.style.right = 'inherit';
}
}

function open(el) {
el.setAttribute("aria-expanded", "true");
positionElement(el);
Expand Down

0 comments on commit 152d794

Please sign in to comment.