help wantedquestion / supportreact
Description
Describe the bug
I have a ModalButton component (in React). My component work well on my app but in my story, when i click on the button it does not display the modal.
To Reproduce
Here the code of my component :
"use client";
import React, {
cloneElement,
ComponentProps,
FunctionComponent,
ReactElement,
ReactNode,
} from "react";
import useModal from "../../../hooks/useModal";
import Modal from "../Modal/Modal";
type ModalButtonProps = {
trigger: ReactElement;
modalProps?: Pick<
ComponentProps<typeof Modal>,
"className" | "header" | "leading" | "size" | "trailing" | "title"
>;
modalContent: ReactNode;
};
const ModalButton: FunctionComponent<ModalButtonProps> = ({
trigger,
modalProps,
modalContent,
}) => {
const modalState = useModal();
return (
<>
{cloneElement(trigger, {
onClick: (event: any) => {
event?.preventDefault();
modalState.open();
},
})}
<Modal
open={modalState.isOpen}
onClose={modalState.close}
{...modalProps}
>
{modalContent}
</Modal>
</>
);
};
export default ModalButton;
The code of the story :
import { Meta, StoryObj } from "@storybook/react";
import Button from "../../components/elements/Button";
import ModalButton from "../../components/modules/ModalButton";
export default {
title: "modules/ModalButton",
component: ModalButton,
args: {
modalContent: <p>Modal content</p>,
},
argTypes: {
trigger: { table: { disable: true } },
modalContent: { table: { disable: true } },
modalProps: { table: { disable: true } },
},
} as Meta<typeof ModalButton>;
type Story = StoryObj<typeof ModalButton>;
export const ButtonTrigger: Story = {
args: {
trigger: <Button>Lorem ipsum</Button>,
},
};
export const AnchorTrigger: Story = {
args: {
trigger: <Button as="a">Lorem ipsum</Button>,
},
};
System
Environment Info:
System:
OS: Linux 5.4 Ubuntu 20.04.6 LTS (Focal Fossa)
CPU: (16) x64 AMD Ryzen 7 2700 Eight-Core Processor
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.5.0 - /usr/local/bin/npm
Browsers:
Chrome: 116.0.5845.187
npmPackages:
@storybook/addon-actions: ^7.3.1 => 7.3.2
@storybook/addon-essentials: ^7.3.1 => 7.3.2
@storybook/addon-interactions: ^7.3.1 => 7.3.2
@storybook/addon-links: ^7.3.1 => 7.3.2
@storybook/addon-mdx-gfm: ^7.3.1 => 7.3.2
@storybook/nextjs: ^7.3.1 => 7.3.2
@storybook/react: ^7.3.1 => 7.3.2
@storybook/testing-library: 0.2.0 => 0.2.0
Additional context
No response