Skip to content

Commit

Permalink
fix(popup): reposition if under axis
Browse files Browse the repository at this point in the history
  • Loading branch information
smbea committed Nov 21, 2023
1 parent f125138 commit 8e05cfd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/features/popup-menu/PopupMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ PopupMenu.prototype._ensureVisible = function(container, position) {
top = position.y - containerBounds.height;
}

// underAxis
if (position.y < documentBounds.top) {
top = position.y + containerBounds.height;
}

return {
x: left,
y: top
Expand Down
23 changes: 23 additions & 0 deletions test/spec/features/popup-menu/PopupMenuSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,29 @@ describe('features/popup-menu', function() {
}));


it('should open within bounds bellow', inject(function(popupMenu) {

// given
var documentBounds = document.documentElement.getBoundingClientRect();

const y = - 5;
var cursorPosition = { x: documentBounds.left + 100, y: documentBounds.top + y };

// when
popupMenu.open({}, 'custom-provider', cursorPosition);

var menu = queryPopup('.djs-popup');

var menuDimensions = {
width: menu.scrollWidth,
height: menu.scrollHeight
};

// then
expect(menu.offsetTop).to.be.closeTo(y + menuDimensions.height, 3);
}));


it('should open within bounds above (limited client rect height)', inject(

function(popupMenu) {
Expand Down

0 comments on commit 8e05cfd

Please sign in to comment.