fix: radix auto focus issue
Signed-off-by: Innei <i@innei.in>
This commit is contained in:
parent
631156e3f5
commit
b3d05b42e9
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ export interface ModalProps {
|
|||
resizeDefaultSize?: { width: number; height: number }
|
||||
|
||||
modal?: boolean
|
||||
|
||||
autoFocus?: boolean
|
||||
}
|
||||
export interface ModalStackOptions {
|
||||
wrapper?: FC
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue