I did some changes and made function if you want to call it on the onSubmit I added an id in the close button: id="closeDialog" const DialogContent = React.forwardRef< // ... <DialogPrimitive.Close id="closeDialog" className="..." > // ... </DialogPortal> )); DialogContent.displayName = DialogPrimitive.Content.displayName; then exported a dialogClose() const dialogClose = () => { document.getElementById('closeDialog')?.click(); }; and now I can call this inside a function for example, after validating with zod a form