fix(modal): prevent auto focus restore on close to avoid page scroll (#316)

* fix(dialog): prevent auto focus restore on close to avoid page scroll

When a modal is closed, Radix Dialog by default restores focus to the
trigger element. This causes the page to scroll to that element if it's
not in the viewport, leading to unexpected scrolling behavior after
editing forwards or other items.

Entire-Checkpoint: 78b48b74a841

* fix(modal): prevent auto focus restore on close in ModalContent

Ensure onCloseAutoFocus is applied after props spread to prevent override.
This fixes page scroll to top after closing modal on second edit.
This commit is contained in:
sagit
2026-03-13 17:35:18 +08:00
committed by GitHub
parent f1cad30f44
commit e194813f3b
@@ -145,6 +145,7 @@ export function ModalContent({
return (
<BaseDialogContent
{...props}
className={cn(
mapSize(resolvedSize),
context?.classNames?.base,
@@ -157,7 +158,9 @@ export function ModalContent({
className,
)}
showCloseButton={false}
{...props}
onCloseAutoFocus={(e) => {
e.preventDefault();
}}
>
{renderedChildren}
</BaseDialogContent>