Skip to content

Commit 8cf68d4

Browse files
ContextMenu: fix max height calculation (DevExpress#30250)
1 parent f93dd0b commit 8cf68d4

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

packages/devextreme/js/__internal/ui/context_menu/m_context_menu.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,11 @@ class ContextMenu extends MenuBase {
689689
$submenu.css('height', isNestedSubmenu ? menuHeight : '100%');
690690
}
691691

692+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
693+
_getMaxUsableSpace(offsetTop: number, windowHeight: number, anchorHeight: number): number {
694+
return windowHeight;
695+
}
696+
692697
_getMaxHeight(anchor, considerAnchorHeight = true) {
693698
const windowHeight = getOuterHeight(window);
694699
const isAnchorRenderer = isRenderer(anchor);
@@ -702,7 +707,7 @@ class ContextMenu extends MenuBase {
702707
const offsetTop = anchor[0].getBoundingClientRect().top;
703708
const anchorHeight = getOuterHeight(anchor);
704709
const availableHeight = considerAnchorHeight
705-
? Math.max(offsetTop, windowHeight - offsetTop - anchorHeight)
710+
? this._getMaxUsableSpace(offsetTop, windowHeight, anchorHeight)
706711
: Math.max(offsetTop + anchorHeight, windowHeight - offsetTop);
707712

708713
return availableHeight - SUBMENU_PADDING;

packages/devextreme/js/__internal/ui/menu/m_submenu.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class Submenu extends ContextMenu {
2424

2525
_dataAdapter: any;
2626

27+
_getMaxUsableSpace(offsetTop: number, windowHeight: number, anchorHeight: number): number {
28+
return Math.max(offsetTop, windowHeight - offsetTop - anchorHeight);
29+
}
30+
2731
_getDefaultOptions() {
2832
return extend(super._getDefaultOptions(), {
2933
orientation: 'horizontal',

packages/devextreme/testing/tests/DevExpress.ui.widgets/contextMenu.tests.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,33 @@ QUnit.module('Rendering Scrollable', moduleConfig, () => {
769769
'expanded item still visible'
770770
);
771771
});
772+
773+
QUnit.test('Context menu height should fit viewport minus borders and padding', function(assert) {
774+
new ContextMenu(this.$element, {
775+
target: $('#menuTarget'),
776+
items: Array.from({ length: 1000 }, (_, i) => ({
777+
text: `item ${i + 1}`,
778+
})),
779+
visible: false,
780+
position: {
781+
at: 'bottom center',
782+
my: 'top center',
783+
of: $('#menuShower'),
784+
},
785+
});
786+
787+
$('#menuTarget').trigger('dxcontextmenu');
788+
789+
const $itemsContainer = $('.dx-scrollable-container');
790+
791+
assert.roughEqual(
792+
$itemsContainer.height(),
793+
$(window).height() - 2 * BORDER_WIDTH - SUBMENU_PADDING,
794+
1,
795+
'height window vs container',
796+
);
797+
});
798+
772799
});
773800
});
774801

0 commit comments

Comments
 (0)