fix: radix auto focus issue

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-09-16 22:28:31 +08:00
parent 631156e3f5
commit b3d05b42e9
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
3 changed files with 15 additions and 3 deletions

View File

@ -67,6 +67,7 @@ export const ModalInternal = memo(
resizeable = false,
resizeDefaultSize,
modal = true,
autoFocus = true,
} = item
const setStack = useSetAtom(modalStackAtom)
@ -243,6 +244,15 @@ export const ModalInternal = memo(
},
[canClose, clickOutsideToDismiss, dismiss, modal, noticeModal],
)
const openAutoFocus = useCallback(
(event: Event) => {
if (!autoFocus) {
event.preventDefault()
}
},
[autoFocus],
)
useImperativeHandle(ref, () => modalElementRef.current!)
if (CustomModalComponent) {
return (
@ -250,7 +260,7 @@ export const ModalInternal = memo(
<Dialog.Root open onOpenChange={onClose} modal={modal}>
<Dialog.Portal>
<Dialog.DialogTitle className="sr-only">{title}</Dialog.DialogTitle>
<Dialog.Content asChild>
<Dialog.Content asChild onOpenAutoFocus={openAutoFocus}>
<div
ref={edgeElementRef}
className={cn(
@ -288,7 +298,7 @@ export const ModalInternal = memo(
<Wrapper>
<Dialog.Root modal={modal} open onOpenChange={onClose}>
<Dialog.Portal>
<Dialog.Content asChild>
<Dialog.Content asChild onOpenAutoFocus={openAutoFocus}>
<div
ref={edgeElementRef}
style={zIndexStyle}

View File

@ -29,6 +29,8 @@ export interface ModalProps {
resizeDefaultSize?: { width: number; height: number }
modal?: boolean
autoFocus?: boolean
}
export interface ModalStackOptions {
wrapper?: FC

View File

@ -255,7 +255,7 @@ const createRelatedEntryLink = (variant: "toast" | "modal") => (props: LinkProps
} else {
present({
...basePresentProps,
autoFocus: false,
modalClassName:
"relative mx-auto mt-[10vh] scrollbar-none max-w-full overflow-auto px-2 lg:max-w-[65rem] lg:p-0",
// eslint-disable-next-line @eslint-react/no-nested-components