Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu: fix unable to unselect an menuitem (T1253750) #28402

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading