-
Notifications
You must be signed in to change notification settings - Fork 35
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a programmatic way to close the modal window #85
Comments
Hey, there is example in the docs how to do it, please refer to it. It works as expected https://tgui.xelene.me/?path=/docs/overlays-modal--documentation#controlled export const Controlled: Story = {
args: {
...Playground.args,
},
render: (args) => {
const [isOpen, setIsOpen] = useState(args.open);
const [isFetching, setIsFetching] = useState(false);
const fetchAndClose = () => {
setIsFetching(true);
setTimeout(() => {
setIsFetching(false);
setIsOpen(false);
}, 1000);
};
return (
<Placeholder
header="This modal will be closed after 1000ms, click fetch"
description="Click fetch"
action={<Button size="m" onClick={() => setIsOpen(true)}>Open again</Button>}
>
<Modal
{...args}
trigger={undefined}
open={isOpen}
onOpenChange={setIsOpen}
>
<Placeholder action={(
<Button
size="m"
loading={isFetching}
onClick={fetchAndClose}
>
Fetch data and close
</Button>
)} />
</Modal>
</Placeholder>
);
},
decorators: [DecoratorFullScreen],
}; |
This example shows how to close the modal by the parent component, while I'm asking how to close it by itself. You might say that this is not "react-way", but why is there a |
If you want to close the modal in any custom way, you need to use the |
My modal does submit some action and I want it to close itself after the action's Promise is resolved. There are 2 ways to open a modal: by directly passing the
open
prop or bytrigger
element. Inside you can use theModal.Close
component to close the modal in its native way. But there is no other way. Also, there is noforwardRef
onModal.Close
, so I can't trigger a click event on the element. So I ended up with the following code:So it would be nice to provide some imperative property on the
Modal
component, that will let the developer close the modal in its native way regardless of the way it was opened.The text was updated successfully, but these errors were encountered: