diff --git a/site/src/components/MoreMenu/MoreMenu.stories.tsx b/site/src/components/MoreMenu/MoreMenu.stories.tsx new file mode 100644 index 0000000000000..0ad43194ced29 --- /dev/null +++ b/site/src/components/MoreMenu/MoreMenu.stories.tsx @@ -0,0 +1,59 @@ +import GrassIcon from "@mui/icons-material/Grass"; +import KitesurfingIcon from "@mui/icons-material/Kitesurfing"; +import { action } from "@storybook/addon-actions"; +import type { Meta, StoryObj } from "@storybook/react"; +import { expect, screen, userEvent, waitFor, within } from "@storybook/test"; +import { + MoreMenu, + MoreMenuContent, + MoreMenuItem, + MoreMenuTrigger, + ThreeDotsButton, +} from "./MoreMenu"; + +const meta: Meta = { + title: "components/MoreMenu", + component: MoreMenu, +}; + +export default meta; +type Story = StoryObj; + +const Example: Story = { + args: { + children: ( + <> + + + + + + + Touch grass + + + + Touch water + + + + ), + }, + play: async ({ canvasElement, step }) => { + const canvas = within(canvasElement); + + await step("Open menu", async () => { + await userEvent.click( + canvas.getByRole("button", { name: "More options" }), + ); + await waitFor(() => + Promise.all([ + expect(screen.getByText(/touch grass/i)).toBeInTheDocument(), + expect(screen.getByText(/touch water/i)).toBeInTheDocument(), + ]), + ); + }); + }, +}; + +export { Example as MoreMenu }; diff --git a/site/src/components/MoreMenu/MoreMenu.tsx b/site/src/components/MoreMenu/MoreMenu.tsx index c1b1a2f7f4ada..62494b781872e 100644 --- a/site/src/components/MoreMenu/MoreMenu.tsx +++ b/site/src/components/MoreMenu/MoreMenu.tsx @@ -111,11 +111,7 @@ export const MoreMenuItem: FC = ({ danger = false, ...menuItemProps }) => { - const ctx = useContext(MoreMenuContext); - - if (!ctx) { - throw new Error("MoreMenuItem must be used inside of MoreMenu"); - } + const menu = useMoreMenuContext(); return ( = ({ onClick={(e) => { menuItemProps.onClick && menuItemProps.onClick(e); if (closeOnClick) { - ctx.close(); + menu.close(); } }} />