Skip to content

Commit

Permalink
fix(dropdown): fix duplicative variable and parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
monicawheeler authored and kajabi-bot committed Mar 13, 2024
1 parent f7b04e6 commit b1177c9
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/sage-system/lib/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +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 (!wrapperRef.current) return;
if (!dropdownElement) return;

let directionX = null;
let directionY = null;
const el = wrapperRef.current;

// 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 @@ -215,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 @@ -257,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 @@ -266,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 b1177c9

Please sign in to comment.