Skip to content

Commit 6ddd567

Browse files
ContextMenu: show submenu synchronously if submenu delay set to 0 (T1247739) (#29437)
1 parent 9925a14 commit 6ddd567

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { asyncNoop, noop } from '@js/core/utils/common';
66
import { extend } from '@js/core/utils/extend';
77
import { each } from '@js/core/utils/iterator';
88
import { isDefined, isObject, isPlainObject } from '@js/core/utils/type';
9+
import type { DxEvent } from '@js/events';
910
import type { dxMenuBaseOptions } from '@js/ui/context_menu/ui.menu_base';
1011
import type { Item } from '@js/ui/menu';
1112
import { render } from '@js/ui/widget/utils.ink_ripple';
@@ -202,7 +203,7 @@ class MenuBase extends HierarchicalCollectionWidget<Properties> {
202203
const { items } = itemData;
203204
let $popOutContainer;
204205

205-
if (items && items.length) {
206+
if (items?.length) {
206207
const $popOutImage = $('<div>').addClass(DX_MENU_ITEM_POPOUT_CLASS);
207208
$popOutContainer = $('<span>').addClass(DX_MENU_ITEM_POPOUT_CONTAINER_CLASS).append($popOutImage);
208209
}
@@ -312,16 +313,22 @@ class MenuBase extends HierarchicalCollectionWidget<Properties> {
312313
return `.${DX_MENU_ITEM_WRAPPER_CLASS}`;
313314
}
314315

315-
_hoverStartHandler(e) {
316+
_hoverStartHandler(e: DxEvent): void {
316317
const $itemElement = this._getItemElementByEventArgs(e);
317318

318319
if (!$itemElement || this._isItemDisabled($itemElement)) return;
319320

320321
e.stopPropagation();
321322

322323
if (this._getShowSubmenuMode() === 'onHover') {
323-
clearTimeout(this._showSubmenusTimeout);
324-
this._showSubmenusTimeout = setTimeout(this._showSubmenu.bind(this, $itemElement), this._getSubmenuDelay('show'));
324+
const submenuDelay = this._getSubmenuDelay('show');
325+
326+
if (submenuDelay === 0) {
327+
this._showSubmenu($itemElement);
328+
} else {
329+
clearTimeout(this._showSubmenusTimeout);
330+
this._showSubmenusTimeout = setTimeout(this._showSubmenu.bind(this, $itemElement), submenuDelay);
331+
}
325332
}
326333
}
327334

@@ -382,7 +389,7 @@ class MenuBase extends HierarchicalCollectionWidget<Properties> {
382389
}
383390

384391
_hasSubmenu(node) {
385-
return node && node.internalFields.childrenKeys.length;
392+
return node?.internalFields.childrenKeys.length;
386393
}
387394

388395
_renderContentImpl() {
@@ -459,7 +466,7 @@ class MenuBase extends HierarchicalCollectionWidget<Properties> {
459466

460467
const $node = $nodeElement ?? this._createDOMElement($nodeContainer);
461468

462-
if (items[index + 1] && items[index + 1].beginGroup) {
469+
if (items[index + 1]?.beginGroup) {
463470
$node.addClass(DX_MENU_ITEM_LAST_GROUP_ITEM);
464471
}
465472

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,30 @@ QUnit.module('Showing and hiding submenus', moduleConfig, () => {
11611161
assert.ok($rootItem.hasClass(DX_MENU_ITEM_EXPANDED_CLASS), 'expanded class was not removed');
11621162
});
11631163

1164+
[0, { show: 0 }].forEach((delay) => {
1165+
QUnit.test(`submenu should be shown synchronously if showSubmenuMode.delay=${JSON.stringify(delay)} (T1247739)`, function(assert) {
1166+
if(!isDeviceDesktop(assert)) {
1167+
return;
1168+
}
1169+
1170+
const instance = new ContextMenu(this.$element, {
1171+
items: [{ text: 1, items: [{ text: 11 }] }],
1172+
visible: true,
1173+
showSubmenuMode: { name: 'onHover', delay },
1174+
});
1175+
1176+
const $itemsContainer = instance.itemsContainer();
1177+
const $rootItem = $itemsContainer.find(`.${DX_MENU_ITEM_CLASS}`).eq(0);
1178+
1179+
$($itemsContainer).trigger($.Event('dxhoverstart', { target: $rootItem.get(0) }));
1180+
1181+
const $submenus = $rootItem.find(`.${DX_SUBMENU_CLASS}`);
1182+
1183+
assert.strictEqual($submenus.length, 1, 'submenu was rendered');
1184+
assert.strictEqual($submenus.eq(0).is(':visible'), true, 'submenu was expanded');
1185+
});
1186+
});
1187+
11641188
QUnit.test('context menu should not blink after second hover on root item', function(assert) {
11651189
if(!isDeviceDesktop(assert)) {
11661190
return;

0 commit comments

Comments
 (0)