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

fix: reset overlay position target to avoid closing after items change (#7702) (CP: 24.4) #7705

Merged
merged 1 commit into from
Aug 29, 2024
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
7 changes: 7 additions & 0 deletions packages/menu-bar/src/vaadin-menu-bar-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,13 @@ export const MenuBarMixin = (superClass) =>
this._expandedButton = button;

requestAnimationFrame(async () => {
// After changing items, buttons are recreated so the old button is
// no longer in the DOM. Reset position target to null to prevent
// overlay from closing due to target width / height equal to 0.
if (overlay.positionTarget && !overlay.positionTarget.isConnected) {
overlay.positionTarget = null;
}

button.dispatchEvent(
new CustomEvent('opensubmenu', {
detail: {
Expand Down
16 changes: 16 additions & 0 deletions packages/menu-bar/test/sub-menu.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,22 @@ describe('sub-menu', () => {
expect(subMenu.opened).to.be.true;
});

it('should reopen sub-menu after updating items', async () => {
buttons[0].click();
await nextRender();

document.body.click();
await nextRender();

menu.items = [menu.items[0]];
await nextRender();

buttons = menu._buttons;
buttons[0].click();
await nextRender();
expect(subMenu.opened).to.be.true;
});

it('should dispatch item-selected event on leaf button click', () => {
const spy = sinon.spy();
menu.addEventListener('item-selected', spy);
Expand Down
Loading