Skip to content

Commit b4dfade

Browse files
web-padawanclaude
andauthored
fix: preserve active attribute on menu-bar button while submenu is open (#11331)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cae25de commit b4dfade

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

packages/menu-bar/src/vaadin-menu-bar-button.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ class MenuBarButton extends Button {
3838
this.__triggeredWithActiveKeys = null;
3939
}
4040

41+
/**
42+
* Override to preserve the `active` attribute while the button's
43+
* sub-menu is expanded, so that the pressed visual state remains.
44+
*
45+
* @param {boolean} active
46+
* @protected
47+
* @override
48+
*/
49+
_setActive(active) {
50+
if (!active && this.hasAttribute('expanded')) {
51+
return;
52+
}
53+
super._setActive(active);
54+
}
55+
4156
/**
4257
* Override method inherited from `ButtonMixin` to allow keyboard navigation with
4358
* arrow keys in the menu bar when the button is focusable in the disabled state.

packages/menu-bar/test/sub-menu.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,39 @@ describe('sub-menu', () => {
473473
expect(buttons[0].hasAttribute('expanded')).to.be.false;
474474
});
475475
});
476+
477+
describe('active attribute', () => {
478+
it('should preserve active attribute on button while sub-menu is open on Enter', async () => {
479+
enter(buttons[0]);
480+
await nextRender();
481+
expect(subMenu.opened).to.be.true;
482+
expect(buttons[0].hasAttribute('active')).to.be.true;
483+
});
484+
485+
it('should preserve active attribute on button while sub-menu is open on Space', async () => {
486+
space(buttons[0]);
487+
await nextRender();
488+
expect(subMenu.opened).to.be.true;
489+
expect(buttons[0].hasAttribute('active')).to.be.true;
490+
});
491+
492+
it('should preserve active attribute on button while sub-menu is open on click', async () => {
493+
buttons[0].click();
494+
await nextRender();
495+
expect(subMenu.opened).to.be.true;
496+
expect(buttons[0].hasAttribute('active')).to.be.true;
497+
});
498+
499+
it('should remove active attribute when sub-menu is closed', async () => {
500+
buttons[0].click();
501+
await nextRender();
502+
expect(buttons[0].hasAttribute('active')).to.be.true;
503+
504+
buttons[0].click();
505+
await nextRender();
506+
expect(buttons[0].hasAttribute('active')).to.be.false;
507+
});
508+
});
476509
});
477510

478511
describe('open on hover', () => {

0 commit comments

Comments
 (0)