Skip to content

Commit fe7ccba

Browse files
authored
fix: observe parent resize to detect overflow (#3824)
1 parent 2e248c0 commit fe7ccba

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎packages/menu-bar/src/vaadin-menu-bar-buttons-mixin.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ export const ButtonsMixin = (superClass) =>
2828
return ['_menuItemsChanged(items, items.splices)'];
2929
}
3030

31+
/**
32+
* Override getter from `ResizeMixin` to observe parent.
33+
*
34+
* @protected
35+
* @override
36+
*/
37+
get _observeParent() {
38+
return true;
39+
}
40+
3141
/** @protected */
3242
ready() {
3343
super.ready();

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,72 @@ describe('responsive behaviour in container', () => {
513513
});
514514
});
515515

516+
describe('parent resize', () => {
517+
let container, text, menu, buttons;
518+
519+
beforeEach(() => {
520+
container = fixtureSync('<div style="display: flex; max-width: 300px"></div>');
521+
text = document.createElement('div');
522+
text.textContent = 'Sibling';
523+
menu = document.createElement('vaadin-menu-bar');
524+
menu.items = [{ text: 'Item 1' }, { text: 'Item 2' }, { text: 'Item 3' }, { text: 'Item 4' }];
525+
menu.style.minWidth = '100px';
526+
});
527+
528+
describe('container', () => {
529+
beforeEach(async () => {
530+
container.append(text, menu);
531+
await onceResized(menu);
532+
buttons = menu._buttons;
533+
});
534+
535+
it('should show buttons when container width increases and menu-bar width stays the same', async () => {
536+
assertHidden(buttons[2]);
537+
assertHidden(buttons[3]);
538+
539+
container.style.maxWidth = '400px';
540+
await onceResized(menu);
541+
542+
assertVisible(buttons[2]);
543+
assertVisible(buttons[3]);
544+
});
545+
546+
it('should show buttons after attaching another container and increasing its width', async () => {
547+
const other = document.createElement('div');
548+
other.style.display = 'flex';
549+
other.style.maxWidth = '300px';
550+
container.parentNode.appendChild(other);
551+
552+
other.append(text, menu);
553+
other.style.maxWidth = '400px';
554+
await onceResized(menu);
555+
556+
assertVisible(buttons[2]);
557+
assertVisible(buttons[3]);
558+
});
559+
});
560+
561+
describe('shadow host', () => {
562+
beforeEach(async () => {
563+
container.attachShadow({ mode: 'open' });
564+
container.shadowRoot.append(text, menu);
565+
await onceResized(menu);
566+
buttons = menu._buttons;
567+
});
568+
569+
it('should show buttons when shadow host width increases and menu-bar width stays the same', async () => {
570+
assertHidden(buttons[2]);
571+
assertHidden(buttons[3]);
572+
573+
container.style.maxWidth = '400px';
574+
await onceResized(menu);
575+
576+
assertVisible(buttons[2]);
577+
assertVisible(buttons[3]);
578+
});
579+
});
580+
});
581+
516582
describe('item components', () => {
517583
let menu, buttons, overflow;
518584

0 commit comments

Comments
 (0)