Skip to content

Commit

Permalink
ContextMenu: no error should be raised on disabled submenu item click…
Browse files Browse the repository at this point in the history
… (T1218229) (#26733)
  • Loading branch information
Zedwag authored Feb 22, 2024
1 parent 1cafb81 commit 667d17b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/devextreme/js/ui/context_menu/ui.menu_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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, () => {
Expand Down

0 comments on commit 667d17b

Please sign in to comment.