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(menu): add default value to inline-size in small screens (VIV-2006) #2078

Merged
merged 3 commits into from
Jan 14, 2025
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
5 changes: 5 additions & 0 deletions libs/components/src/lib/menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ Use the `--menu-max-inline-size` variable to set the menu's inline size.

- Default: `max-content`

<vwc-note connotation="information" icon="info-solid">
<p>When setting a value to the <code>max-inline-size</code> - make sure the menu is OK in small resolutions as well. </p>
<p>In mobile, the <code>max-inline-size</code> is <code>300px</code> by default, but can be changed with the css-variable. </p>
</vwc-note>

```html preview 150px
<style>
vwc-menu {
Expand Down
9 changes: 8 additions & 1 deletion libs/components/src/lib/menu/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
gap: 8px;
inline-size: max-content;
max-block-size: var(#{variables.$menu-block-size}, 408px);
max-inline-size: var(#{variables.$menu-max-inline-size});
min-inline-size: var(#{variables.$menu-min-inline-size});
padding-block: 8px;

@media not all and (width >= 600px) {
max-inline-size: var(#{variables.$menu-max-inline-size}, 300px);
}

@media (width >= 600px) {
max-inline-size: var(#{variables.$menu-max-inline-size});
}
}

::slotted(a) {
Expand Down
39 changes: 39 additions & 0 deletions libs/components/src/lib/menu/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,44 @@ async function testAbsolutStrategy({ page }: { page: Page }) {
);
}

async function testMobileInlineSize({ page }: { page: Page }) {
const template = `
<style>
.wrapper {
width: 360px;
height: 400px;
}
</style>
<div class="wrapper">
<vwc-menu open placement="bottom-start" >
<vwc-button slot="anchor" label="Menu" appearance="outlined"></vwc-button>
<vwc-menu-item text="Menu item 1 with long text that gets ellipsis"></vwc-menu-item>
<vwc-menu-item text="Menu item 2 with long text that gets ellipsis"></vwc-menu-item>
<vwc-menu-item text="Menu item 3 with long text that gets ellipsis"></vwc-menu-item>
</vwc-menu>
</div>`;

page.setViewportSize({ width: 360, height: 400 });

await loadComponents({
page,
components,
});
await loadTemplate({
page,
template,
});

const testWrapper = await page.$('#wrapper');

await page.waitForLoadState('networkidle');

expect(await testWrapper?.screenshot()).toMatchSnapshot(
'snapshots/mobile-menu.png',
{ maxDiffPixelRatio: 0.01 }
);
}

test('should show the component', async ({ page }: { page: Page }) => {
const template = `
<style>
Expand Down Expand Up @@ -89,3 +127,4 @@ test('should show the component', async ({ page }: { page: Page }) => {
});

test('menu with absolute strategy', testAbsolutStrategy);
test('menu with max-inline-size in mobile', testMobileInlineSize);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading