From 667d17be0596d5ef9a7d83b54a09d3cdb98632d1 Mon Sep 17 00:00:00 2001 From: Alexander Kozlovskiy Date: Thu, 22 Feb 2024 07:57:14 -0600 Subject: [PATCH] ContextMenu: no error should be raised on disabled submenu item click (T1218229) (#26733) --- .../js/ui/context_menu/ui.menu_base.js | 2 +- .../contextMenu.tests.js | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/devextreme/js/ui/context_menu/ui.menu_base.js b/packages/devextreme/js/ui/context_menu/ui.menu_base.js index f428470a22db..e7a4d95c600a 100644 --- a/packages/devextreme/js/ui/context_menu/ui.menu_base.js +++ b/packages/devextreme/js/ui/context_menu/ui.menu_base.js @@ -555,7 +555,7 @@ class MenuBase extends HierarchicalCollectionWidget { const { event, itemData } = actionArgs.args[0]; const $itemElement = this._getItemElementByEventArgs(event); - const link = $itemElement.find(`.${ITEM_URL_CLASS}`).get(0); + const link = $itemElement && $itemElement.find(`.${ITEM_URL_CLASS}`).get(0); if(itemData.url && link) { link.click(); diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets/contextMenu.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets/contextMenu.tests.js index 834077fa539b..b5a27a5041af 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets/contextMenu.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets/contextMenu.tests.js @@ -33,6 +33,7 @@ const DX_MENU_PHONE_CLASS = 'dx-menu-phone-overlay'; const DX_MENU_ITEM_SELECTED_CLASS = 'dx-menu-item-selected'; const DX_STATE_HOVER_CLASS = 'dx-state-hover'; const DX_STATE_FOCUSED_CLASS = 'dx-state-focused'; +const DX_STATE_DISABLED_CLASS = 'dx-state-disabled'; const DX_MENU_ITEM_EXPANDED_CLASS = 'dx-menu-item-expanded'; const DX_MENU_ITEM_POPOUT_CLASS = 'dx-menu-item-popout'; const DX_SUBMENU_CLASS = 'dx-submenu'; @@ -1569,6 +1570,27 @@ QUnit.module('Behavior', moduleConfig, () => { fx.stop = origFxStop; } }); + + QUnit.test('Click on disabled submenu item should not raise an error (T1218229)', function(assert) { + assert.expect(0); + + const instance = new ContextMenu(this.$element, { + items: [{ text: 'item 1', items: [{ text: 'subitem 1', disabled: true }] }], + target: '#menuTarget', + visible: true + }); + const $rootItem = instance.itemsContainer().find('.' + DX_MENU_ITEM_CLASS).eq(0); + + $($rootItem).trigger('dxclick'); + + const $disabledItem = instance.itemsContainer().find(`.${DX_STATE_DISABLED_CLASS}.${DX_MENU_ITEM_CLASS}`); + + try { + $($disabledItem).parent().trigger('dxclick'); + } catch(e) { + assert.ok(false); + } + }); }); QUnit.module('Selection', moduleConfig, () => {