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: observe parent resize to detect overflow (#3824) (CP: 23.0) #3836

Merged
merged 1 commit into from
May 12, 2022
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
10 changes: 10 additions & 0 deletions packages/menu-bar/src/vaadin-menu-bar-buttons-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export const ButtonsMixin = (superClass) =>
return ['_menuItemsChanged(items, items.splices)'];
}

/**
* Override getter from `ResizeMixin` to observe parent.
*
* @protected
* @override
*/
get _observeParent() {
return true;
}

/** @protected */
ready() {
super.ready();
Expand Down
66 changes: 66 additions & 0 deletions packages/menu-bar/test/menu-bar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,72 @@ describe('responsive behaviour in container', () => {
});
});

describe('parent resize', () => {
let container, text, menu, buttons;

beforeEach(() => {
container = fixtureSync('<div style="display: flex; max-width: 300px"></div>');
text = document.createElement('div');
text.textContent = 'Sibling';
menu = document.createElement('vaadin-menu-bar');
menu.items = [{ text: 'Item 1' }, { text: 'Item 2' }, { text: 'Item 3' }, { text: 'Item 4' }];
menu.style.minWidth = '100px';
});

describe('container', () => {
beforeEach(async () => {
container.append(text, menu);
await onceResized(menu);
buttons = menu._buttons;
});

it('should show buttons when container width increases and menu-bar width stays the same', async () => {
assertHidden(buttons[2]);
assertHidden(buttons[3]);

container.style.maxWidth = '400px';
await onceResized(menu);

assertVisible(buttons[2]);
assertVisible(buttons[3]);
});

it('should show buttons after attaching another container and increasing its width', async () => {
const other = document.createElement('div');
other.style.display = 'flex';
other.style.maxWidth = '300px';
container.parentNode.appendChild(other);

other.append(text, menu);
other.style.maxWidth = '400px';
await onceResized(menu);

assertVisible(buttons[2]);
assertVisible(buttons[3]);
});
});

describe('shadow host', () => {
beforeEach(async () => {
container.attachShadow({ mode: 'open' });
container.shadowRoot.append(text, menu);
await onceResized(menu);
buttons = menu._buttons;
});

it('should show buttons when shadow host width increases and menu-bar width stays the same', async () => {
assertHidden(buttons[2]);
assertHidden(buttons[3]);

container.style.maxWidth = '400px';
await onceResized(menu);

assertVisible(buttons[2]);
assertVisible(buttons[3]);
});
});
});

describe('item components', () => {
let menu, buttons, overflow;

Expand Down