-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
How to replace default close button for Dialog ? #1871
Comments
I have the same doubt. |
Did you check this? |
The issue would be to remove the current close button in order to replace it with a custom one. |
@yogiyendri 1. Declare like this![]() 2. Use when you want![]() |
This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you. |
If you want to use your own custom icon, either in the Dialog or in the Sheet, you might need to add an extra prop to allow for this.
type ModifiedDialogContentType = React.ForwardRefExoticComponent<
Note how I used conditional rendering to hide/show the close button, by defining a prop called Thanks |
here i want to hide default close (x) button place on top right. |
you managed to? |
@ArsenKakasyan , I did get to hide it using ref. It is the only child of type button in the dialog content that is why i used a generic selector. You can be more specific with the selector. Not the best way of doing this but it works fine for me.
|
It can be controled by adding attribute to DialogContent. const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
hideCloseButton?: boolean;
}
>(({className, children, hideCloseButton, ...props}, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg',
className,
)}
{...props}>
{children}
{!hideCloseButton && (
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Content>
</DialogPortal>
));
DialogContent.displayName = DialogPrimitive.Content.displayName; |
Modify your dialog content code to:
|
When we update the plugin in the future, this code may not work entire code will be replaced by shadcn component |
@shadcn Please consider of adding the prop |
Hello, it may be so obvious but I didn't found way to replace default close button with my custom icon, In the docs I've found that custom close button can be added but didn't mentioned how to hide the existing one or replace the icon.
I really like this UI, unfortunately the docs seems very incomplete. Can I get some help on this?
Why this is an issue? becoz I think there's should be way to hide / replace default close button.
The text was updated successfully, but these errors were encountered: