Skip to content

Commit 092fba7

Browse files
ContextMenu: fix max height calculation (#30249)
1 parent fbb72df commit 092fba7

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
@@ -720,6 +720,11 @@ class ContextMenu extends MenuBase {
720720
$submenu.css('height', isNestedSubmenu ? menuHeight : '100%');
721721
}
722722

723+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
724+
_getMaxUsableSpace(offsetTop: number, windowHeight: number, anchorHeight: number): number {
725+
return windowHeight;
726+
}
727+
723728
_getMaxHeight(anchor, considerAnchorHeight = true) {
724729
const windowHeight = getOuterHeight(window);
725730
const isAnchorRenderer = isRenderer(anchor);
@@ -733,7 +738,7 @@ class ContextMenu extends MenuBase {
733738
const offsetTop = anchor[0].getBoundingClientRect().top;
734739
const anchorHeight = getOuterHeight(anchor);
735740
const availableHeight = considerAnchorHeight
736-
? Math.max(offsetTop, windowHeight - offsetTop - anchorHeight)
741+
? this._getMaxUsableSpace(offsetTop, windowHeight, anchorHeight)
737742
: Math.max(offsetTop + anchorHeight, windowHeight - offsetTop);
738743

739744
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)