-
I want to close a dialog with a button, is there a way to do this? ideally I would call a method for full control but even a builder to pass would be fine |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If you copied the whole code for the dialog, you should have a little x on the top right of the dialog where you can close the dialog. But if you want a separate close button that exists beside your submit button, you could either call the primitive directly from bits-ui or create your own little component. Here is an example from my code where I made a component that I can use directly from my own Dialog component. <div class="flex items-center justify-end gap-4">
<Dialog.Close>
<Button type="button">Cancel</Button>
</Dialog.Close>
<Button type="submit" variant="primary">Create Stintplan</Button>
</div> And this is my simple <script lang="ts">
import { Dialog as DialogPrimitives } from 'bits-ui';
type $$Props = DialogPrimitives.CloseProps;
</script>
<DialogPrimitives.Close {...$$restProps}>
<slot />
</DialogPrimitives.Close>
|
Beta Was this translation helpful? Give feedback.
-
Another option that I have used is to bind on the
|
Beta Was this translation helpful? Give feedback.
Another option that I have used is to bind on the
open
prop onDialog.Root
and use a button to flip it to false.