Skip to content

Commit c9f49c6

Browse files
ContextMenu: fix max height calculation (DevExpress#30246)
1 parent b808fba commit c9f49c6

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

717+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
718+
_getMaxUsableSpace(offsetTop: number, windowHeight: number, anchorHeight: number): number {
719+
return windowHeight;
720+
}
721+
717722
_getMaxHeight(anchor, considerAnchorHeight = true) {
718723
const windowHeight = getOuterHeight(window);
719724
const isAnchorRenderer = isRenderer(anchor);
@@ -727,7 +732,7 @@ class ContextMenu extends MenuBase {
727732
const offsetTop = anchor[0].getBoundingClientRect().top;
728733
const anchorHeight = getOuterHeight(anchor);
729734
const availableHeight = considerAnchorHeight
730-
? Math.max(offsetTop, windowHeight - offsetTop - anchorHeight)
735+
? this._getMaxUsableSpace(offsetTop, windowHeight, anchorHeight)
731736
: Math.max(offsetTop + anchorHeight, windowHeight - offsetTop);
732737

733738
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
@@ -762,6 +762,33 @@ QUnit.module('Rendering Scrollable', moduleConfig, () => {
762762
'expanded item still visible'
763763
);
764764
});
765+
766+
QUnit.test('Context menu height should fit viewport minus borders and padding', function(assert) {
767+
new ContextMenu(this.$element, {
768+
target: $('#menuTarget'),
769+
items: Array.from({ length: 1000 }, (_, i) => ({
770+
text: `item ${i + 1}`,
771+
})),
772+
visible: false,
773+
position: {
774+
at: 'bottom center',
775+
my: 'top center',
776+
of: $('#menuShower'),
777+
},
778+
});
779+
780+
$('#menuTarget').trigger('dxcontextmenu');
781+
782+
const $itemsContainer = $('.dx-scrollable-container');
783+
784+
assert.roughEqual(
785+
$itemsContainer.height(),
786+
$(window).height() - 2 * BORDER_WIDTH - SUBMENU_PADDING,
787+
1,
788+
'height window vs container',
789+
);
790+
});
791+
765792
});
766793
});
767794

0 commit comments

Comments
 (0)