Skip to content

Commit

Permalink
fix(dropdown): resolve sentry errors in positionElement (#1883)
Browse files Browse the repository at this point in the history
* fix(dropdown): resolve sentry error in positionElement

* test(dropdown): remove trailing spaces

* fix(dropdown): remove trailing whitespace
  • Loading branch information
QuintonJason authored May 6, 2024
1 parent 902990c commit b2585c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/sage-react/lib/Dropdown/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export const Dropdown = ({
const button = el;
const panel = el.lastElementChild;

// if panel is null, return
if (!panel) return;

// Dimensions
const buttonDimensions = button.getBoundingClientRect();
const panelDimensions = panel.getBoundingClientRect();
Expand Down
9 changes: 6 additions & 3 deletions packages/sage-system/lib/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,16 @@ Sage.dropdown = (function () {

let directionX = null;
let directionY = null;

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

// if panel is null, return
if (!panel) return;

panel.style.top = ''; // resets the style
panel.style.left = ''; // resets the style
panel.style.right = ''; // resets the style
Expand Down Expand Up @@ -235,7 +238,7 @@ Sage.dropdown = (function () {
const enoughSpaceBelow = viewport.bottom > (offset.bottom + panelHeight);
const enoughSpaceLeft = viewport.left < (offset.left + panelWidth);
const enoughSpaceRight = viewport.right > (offset.right + panelWidth);

// Check if there is enough space to the top or bottom
if (!enoughSpaceBelow && enoughSpaceAbove) {
directionY = 'above';
Expand All @@ -248,7 +251,7 @@ Sage.dropdown = (function () {
} else if (directionY === 'below') {
// find test case
// panel.style.top = 0;
}
}

// Check if there is enough space to the left or right
if (!enoughSpaceRight && enoughSpaceLeft) {
Expand Down

0 comments on commit b2585c4

Please sign in to comment.