Skip to content

Commit

Permalink
Menu: fix unable to unselect an menuitem (T1253750) (#28402)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkithelegendarypokemonster authored Nov 21, 2024
1 parent 67bf694 commit dbd76db
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/devextreme/js/__internal/ui/menu/m_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ class Menu extends MenuBase {

unselectItem(itemElement): void {
this._hideSubmenu(this._visibleSubmenu);
super.selectItem(itemElement);
super.unselectItem(itemElement);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,41 @@ QUnit.module('Menu - selection', {
assert.equal($items.find('.' + DX_MENU_ITEM_TEXT_CLASS).text(), 'item3');
});

QUnit.test('should be able to select an item via .selectItem() (T1253750)', function(assert) {
const menu = createMenu({
items: [
{
text: 'menu item 1',
selectable: true,
},
],
});
const item = $(menu.element).find(`.${DX_MENU_ITEM_CLASS}`).eq(0);

menu.instance.selectItem(item[0]);

assert.strictEqual(item.hasClass(DX_MENU_ITEM_SELECTED_CLASS), true, 'item has the selected class after initialization');
});

QUnit.test('should be able to unselect currently selected item (T1253750)', function(assert) {
const menu = createMenu({
items: [
{
text: 'menu item 1',
selectable: true,
selected: true,
},
],
});
const item = $(menu.element).find(`.${DX_MENU_ITEM_CLASS}`).eq(0);

assert.strictEqual(item.hasClass(DX_MENU_ITEM_SELECTED_CLASS), true, 'item has the selected class after initialization');

menu.instance.unselectItem(item[0]);

assert.strictEqual(item.hasClass(DX_MENU_ITEM_SELECTED_CLASS), false, 'item does not have the selected class after unselecting');
});

QUnit.test('Selection in different submenus', function(assert) {
const items = [
{ text: 'root1', items: [{ text: 'item1-1' }] },
Expand Down

0 comments on commit dbd76db

Please sign in to comment.