huntabyte / bits-ui

The headless components for Svelte.
https://bits-ui.com
MIT License
1.19k stars 86 forks source link

add property to Prevent Dialog from being closed #647

Closed opensas closed 1 week ago

opensas commented 1 month ago

Describe the feature in detail (code, mocks, or screenshots encouraged)

Add properties to prevent the Dialog from being closed by the user

usage: display a "loading please wait" dialog. the dialog will be programmatically close when the process finishes (I couldn't find a way to hide the X button, perhaps there's an easy solution that I missed)

could be a preventScroll: boolean or (also) a showCloseButton (or hideCloseButton): boolean

What type of pull request would this be?

Enhancement

Provide relevant links or additional information.

No response

opensas commented 1 month ago

currently, using shadcn-svelte I did this dirty workaround:

    type $$Props = DialogPrimitive.ContentProps & { hideCloseButton?: boolean };

    let className: $$Props['class'] = undefined;

    export let hideCloseButton = false;
[...]
</script>

<Dialog.Portal>
    <Dialog.Overlay />
    <DialogPrimitive.Content
[...]
    >
        <slot />
        {#if !hideCloseButton}
            <DialogPrimitive.Close
[...]
            </DialogPrimitive.Close>
        {/if}
    </DialogPrimitive.Content>
</Dialog.Portal>
huntabyte commented 1 week ago

Just dont render the close button until your condition is met, or call e.preventDefault on the click handler of the close button.