Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add stories forMoreMenu#12464

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 4 commits intomainfrommore-menu-stories
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
59 changes: 59 additions & 0 deletionssite/src/components/MoreMenu/MoreMenu.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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<typeof MoreMenu> = {
title: "components/MoreMenu",
component: MoreMenu,
};

export default meta;
type Story = StoryObj<typeof MoreMenu>;

const Example: Story = {
args: {
children: (
<>
<MoreMenuTrigger>
<ThreeDotsButton />
</MoreMenuTrigger>
<MoreMenuContent>
<MoreMenuItem onClick={action("grass")}>
<GrassIcon />
Touch grass
</MoreMenuItem>
<MoreMenuItem onClick={action("water")}>
<KitesurfingIcon />
Touch water
</MoreMenuItem>
</MoreMenuContent>
</>
),
},
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 };
8 changes: 2 additions & 6 deletionssite/src/components/MoreMenu/MoreMenu.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,11 +111,7 @@ export const MoreMenuItem: FC<MoreMenuItemProps> = ({
danger = false,
...menuItemProps
}) => {
const ctx = useContext(MoreMenuContext);

if (!ctx) {
throw new Error("MoreMenuItem must be used inside of MoreMenu");
}
const menu = useMoreMenuContext();

return (
<MenuItem
Expand All@@ -131,7 +127,7 @@ export const MoreMenuItem: FC<MoreMenuItemProps> = ({
onClick={(e) => {
menuItemProps.onClick && menuItemProps.onClick(e);
if (closeOnClick) {
ctx.close();
menu.close();
}
}}
/>
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp