Skip to content

Commit 6794780

Browse files
authored
fix(DropdownMenu): remove separators in case of empty groups (#2495)
1 parent d716102 commit 6794780

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed
Loading

src/components/DropdownMenu/__tests__/DropdownMenu.visual.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,36 @@ test.describe('DropdownMenu', {tag: '@DropdownMenu'}, () => {
5858
});
5959
});
6060
});
61+
62+
smokeTest('menu with empty groups', async ({page, mount, expectScreenshot}) => {
63+
const props = {
64+
open: true,
65+
items: [
66+
[
67+
{
68+
text: 'level 0',
69+
action: () => {},
70+
},
71+
],
72+
[],
73+
],
74+
};
75+
const component = await mount(
76+
<div
77+
style={{
78+
width: '300px',
79+
height: '150px',
80+
}}
81+
>
82+
<DropdownMenu {...props} />
83+
</div>,
84+
);
85+
86+
await page.getByText('level 0').hover();
87+
88+
await expectScreenshot({
89+
component,
90+
themes: ['light'],
91+
});
92+
});
6193
});

src/components/DropdownMenu/utils/toItemList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function toItemList<
1010
if (Array.isArray(item)) {
1111
const groupItems = toItemList(item, separator, path, index);
1212

13-
if (updatedItems.length !== 0) {
13+
if (updatedItems.length !== 0 && groupItems.length !== 0) {
1414
updatedItems.push(separator);
1515
}
1616

0 commit comments

Comments
 (0)