Skip to content

Commit 98a6a9f

Browse files
committed
fix(menu): DropdownMenu and Menu portal by default
Closes #1264 BREAKING CHANGE: The `DropdownMenu` and `Menu` components portal by default. This should really only affect snapshot tests
1 parent 9632d82 commit 98a6a9f

File tree

6 files changed

+161
-149
lines changed

6 files changed

+161
-149
lines changed

packages/menu/src/DropdownMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const DropdownMenu = forwardRef<HTMLButtonElement, DropdownMenuProps>(
9999
itemRenderer = defaultMenuItemRenderer,
100100
horizontal,
101101
onVisibilityChange,
102-
portal,
102+
portal = true,
103103
portalInto,
104104
portalIntoId,
105105
positionOptions,

packages/menu/src/Menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(
158158
visible,
159159
onRequestClose,
160160
children,
161-
portal,
161+
portal = true,
162162
portalInto,
163163
portalIntoId,
164164
temporary = true,

packages/menu/src/__tests__/DropdownMenu.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { CSSProperties } from "react";
33
import { fireEvent, render } from "@testing-library/react";
44

5-
import { DropdownMenu } from "../DropdownMenu";
5+
import { DropdownMenu, DropdownMenuProps } from "../DropdownMenu";
66
import { MenuItem } from "../MenuItem";
77

88
const getById = (id: string) => {
@@ -14,25 +14,23 @@ const getById = (id: string) => {
1414
return el;
1515
};
1616

17-
const PROPS = {
17+
const PROPS: Omit<DropdownMenuProps, "items"> = {
1818
id: "dropdown",
1919
children: "Dropdown",
2020
};
2121

2222
describe("DropdownMenu", () => {
2323
it("should render correctly with a list of strings, numbers, ListItemProps, ReactElement, or a mixture of all", () => {
2424
const items1 = ["Item 1", "Item 2", "Item 3"];
25-
const { container, rerender } = render(
26-
<DropdownMenu {...PROPS} items={items1} />
27-
);
28-
expect(container).toMatchSnapshot();
25+
const { rerender } = render(<DropdownMenu {...PROPS} items={items1} />);
26+
expect(document.body).toMatchSnapshot();
2927

3028
fireEvent.click(getById("dropdown"));
31-
expect(container).toMatchSnapshot();
29+
expect(document.body).toMatchSnapshot();
3230

3331
const items2 = [0, 1, 2, 3, 4];
3432
rerender(<DropdownMenu {...PROPS} items={items2} />);
35-
expect(container).toMatchSnapshot();
33+
expect(document.body).toMatchSnapshot();
3634

3735
const items3 = [
3836
{
@@ -42,7 +40,7 @@ describe("DropdownMenu", () => {
4240
{ rightAddon: <i>icon</i>, children: "Item 3" },
4341
];
4442
rerender(<DropdownMenu {...PROPS} items={items3} />);
45-
expect(container).toMatchSnapshot();
43+
expect(document.body).toMatchSnapshot();
4644

4745
// Note: no key required
4846
const items4 = [
@@ -54,7 +52,7 @@ describe("DropdownMenu", () => {
5452
4,
5553
];
5654
rerender(<DropdownMenu {...PROPS} items={items4} />);
57-
expect(container).toMatchSnapshot();
55+
expect(document.body).toMatchSnapshot();
5856
});
5957

6058
it("should pass the menuStyle and menuClassName props to the menu correctly", () => {

packages/menu/src/__tests__/Menu.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
} from "@testing-library/react";
77

88
import { DropdownMenuItem } from "../DropdownMenuItem";
9-
import { Menu } from "../Menu";
9+
import { Menu, MenuProps } from "../Menu";
1010

11-
const PROPS = {
11+
const PROPS: MenuProps = {
1212
id: "menu",
1313
controlId: "menu-container",
1414
visible: false,
@@ -51,16 +51,16 @@ const render = (children: ReactElement): RenderResult =>
5151

5252
describe("Menu", () => {
5353
it("should render correctly", () => {
54-
const { container, rerender } = render(<Menu {...PROPS} />);
55-
expect(container).toMatchSnapshot();
54+
const { rerender } = render(<Menu {...PROPS} />);
55+
expect(document.body).toMatchSnapshot();
5656

5757
rerender(<Menu {...PROPS} visible />);
58-
expect(container).toMatchSnapshot();
58+
expect(document.body).toMatchSnapshot();
5959
});
6060

6161
it("should trigger the onRequestClose when an element outside of the menu has been clicked but is not the control element", () => {
6262
const onRequestClose = jest.fn();
63-
const props = {
63+
const props: MenuProps = {
6464
...PROPS,
6565
visible: true,
6666
onRequestClose,
@@ -85,7 +85,7 @@ describe("Menu", () => {
8585

8686
it("should not trigger the onRequestClose prop when a nested dropdown menu is clicked", () => {
8787
const onRequestClose = jest.fn();
88-
const props = {
88+
const props: MenuProps = {
8989
...PROPS,
9090
visible: true,
9191
onRequestClose,

0 commit comments

Comments
 (0)