Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mlaursen committed Nov 24, 2021
1 parent 9632d82 commit 98a6a9f
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 149 deletions.
2 changes: 1 addition & 1 deletion packages/menu/src/DropdownMenu.tsx
Expand Up @@ -99,7 +99,7 @@ export const DropdownMenu = forwardRef<HTMLButtonElement, DropdownMenuProps>(
itemRenderer = defaultMenuItemRenderer,
horizontal,
onVisibilityChange,
portal,
portal = true,
portalInto,
portalIntoId,
positionOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/menu/src/Menu.tsx
Expand Up @@ -158,7 +158,7 @@ export const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(
visible,
onRequestClose,
children,
portal,
portal = true,
portalInto,
portalIntoId,
temporary = true,
Expand Down
18 changes: 8 additions & 10 deletions packages/menu/src/__tests__/DropdownMenu.tsx
Expand Up @@ -2,7 +2,7 @@
import { CSSProperties } from "react";
import { fireEvent, render } from "@testing-library/react";

import { DropdownMenu } from "../DropdownMenu";
import { DropdownMenu, DropdownMenuProps } from "../DropdownMenu";
import { MenuItem } from "../MenuItem";

const getById = (id: string) => {
Expand All @@ -14,25 +14,23 @@ const getById = (id: string) => {
return el;
};

const PROPS = {
const PROPS: Omit<DropdownMenuProps, "items"> = {
id: "dropdown",
children: "Dropdown",
};

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

fireEvent.click(getById("dropdown"));
expect(container).toMatchSnapshot();
expect(document.body).toMatchSnapshot();

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

const items3 = [
{
Expand All @@ -42,7 +40,7 @@ describe("DropdownMenu", () => {
{ rightAddon: <i>icon</i>, children: "Item 3" },
];
rerender(<DropdownMenu {...PROPS} items={items3} />);
expect(container).toMatchSnapshot();
expect(document.body).toMatchSnapshot();

// Note: no key required
const items4 = [
Expand All @@ -54,7 +52,7 @@ describe("DropdownMenu", () => {
4,
];
rerender(<DropdownMenu {...PROPS} items={items4} />);
expect(container).toMatchSnapshot();
expect(document.body).toMatchSnapshot();
});

it("should pass the menuStyle and menuClassName props to the menu correctly", () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/menu/src/__tests__/Menu.tsx
Expand Up @@ -6,9 +6,9 @@ import {
} from "@testing-library/react";

import { DropdownMenuItem } from "../DropdownMenuItem";
import { Menu } from "../Menu";
import { Menu, MenuProps } from "../Menu";

const PROPS = {
const PROPS: MenuProps = {
id: "menu",
controlId: "menu-container",
visible: false,
Expand Down Expand Up @@ -51,16 +51,16 @@ const render = (children: ReactElement): RenderResult =>

describe("Menu", () => {
it("should render correctly", () => {
const { container, rerender } = render(<Menu {...PROPS} />);
expect(container).toMatchSnapshot();
const { rerender } = render(<Menu {...PROPS} />);
expect(document.body).toMatchSnapshot();

rerender(<Menu {...PROPS} visible />);
expect(container).toMatchSnapshot();
expect(document.body).toMatchSnapshot();
});

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

it("should not trigger the onRequestClose prop when a nested dropdown menu is clicked", () => {
const onRequestClose = jest.fn();
const props = {
const props: MenuProps = {
...PROPS,
visible: true,
onRequestClose,
Expand Down

0 comments on commit 98a6a9f

Please sign in to comment.