From 05c3b5842e67959696d3170b5c1e42f98350e7ef Mon Sep 17 00:00:00 2001 From: sagit <36596628+Sagit-chu@users.noreply.github.com> Date: Sat, 14 Mar 2026 09:38:09 +0800 Subject: [PATCH] fix(dialog): prevent both open and close auto focus to avoid page scroll (#317) Add onOpenAutoFocus handler to prevent Radix Dialog from auto-focusing content on open, which can cause unwanted scroll behavior. --- vite-frontend/src/components/ui/dialog.tsx | 5 ++++- vite-frontend/src/shadcn-bridge/heroui/modal.tsx | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/vite-frontend/src/components/ui/dialog.tsx b/vite-frontend/src/components/ui/dialog.tsx index f726608..7e91038 100644 --- a/vite-frontend/src/components/ui/dialog.tsx +++ b/vite-frontend/src/components/ui/dialog.tsx @@ -56,15 +56,18 @@ function DialogContent({ { + e.preventDefault(); + }} onCloseAutoFocus={(e) => { e.preventDefault(); }} - {...props} > {children} {showCloseButton && ( diff --git a/vite-frontend/src/shadcn-bridge/heroui/modal.tsx b/vite-frontend/src/shadcn-bridge/heroui/modal.tsx index fd6244b..dbed70a 100644 --- a/vite-frontend/src/shadcn-bridge/heroui/modal.tsx +++ b/vite-frontend/src/shadcn-bridge/heroui/modal.tsx @@ -158,6 +158,9 @@ export function ModalContent({ className, )} showCloseButton={false} + onOpenAutoFocus={(e) => { + e.preventDefault(); + }} onCloseAutoFocus={(e) => { e.preventDefault(); }}