Skip to content

Commit

Permalink
fix: keep custom class name for overflow menu items (#5774)
Browse files Browse the repository at this point in the history
* Fixed class removal. Next: tests.

* Add test

* Linter fix

* add clarifying comment

---------

Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
  • Loading branch information
roastedcpu and sissbruecker committed Apr 26, 2023
1 parent 1998b38 commit cc7ceef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/menu-bar/src/vaadin-menu-bar-buttons-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ export const ButtonsMixin = (superClass) =>
item.removeAttribute('aria-expanded');
item.removeAttribute('aria-haspopup');
item.removeAttribute('tabindex');
item.removeAttribute('class');
item.classList.remove('vaadin-context-menu-parent-item', 'vaadin-menu-item');
if (item.classList.length === 0) {
item.removeAttribute('class');
}
}

/** @private */
Expand Down
12 changes: 12 additions & 0 deletions packages/menu-bar/test/menu-bar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,18 @@ describe('item components', () => {
await onceResized(menu);
expect(item.getAttributeNames()).to.have.members(itemAttributes);
});

it('should keep the class names when moved to submenu and back', async () => {
// Simulate a custom class name being added through the Flow menu bar item component
const item = buttons[5].firstChild;
item.classList.add('test-class-1');
overflow.click();
await nextRender(subMenu);
subMenu.close();
menu.style.width = 'auto';
await onceResized(menu);
expect(item.classList.contains('test-class-1')).to.be.true;
});
});
});

Expand Down

0 comments on commit cc7ceef

Please sign in to comment.