diff --git a/rsconcept/frontend/src/components/modal/modal-form.tsx b/rsconcept/frontend/src/components/modal/modal-form.tsx index d4d4a473..0928690a 100644 --- a/rsconcept/frontend/src/components/modal/modal-form.tsx +++ b/rsconcept/frontend/src/components/modal/modal-form.tsx @@ -1,5 +1,6 @@ 'use client'; +import { useEffect, useRef } from 'react'; import clsx from 'clsx'; import { type HelpTopic } from '@/features/help'; @@ -74,6 +75,14 @@ export function ModalForm({ }: React.PropsWithChildren) { const hideDialog = useDialogsStore(state => state.hideDialog); + const previousFocusRef = useRef(null); + useEffect(() => { + previousFocusRef.current = document.activeElement as HTMLElement | null; + return () => { + previousFocusRef.current?.focus(); + }; + }, []); + function handleCancel() { onCancel?.(); hideDialog(); diff --git a/rsconcept/frontend/src/components/modal/modal-view.tsx b/rsconcept/frontend/src/components/modal/modal-view.tsx index 7ced8254..071f4d2c 100644 --- a/rsconcept/frontend/src/components/modal/modal-view.tsx +++ b/rsconcept/frontend/src/components/modal/modal-view.tsx @@ -1,5 +1,6 @@ 'use client'; +import { useEffect, useRef } from 'react'; import clsx from 'clsx'; import { BadgeHelp } from '@/features/help/components/badge-help'; @@ -36,6 +37,14 @@ export function ModalView({ const hideDialog = useDialogsStore(state => state.hideDialog); useEscapeKey(hideDialog); + const previousFocusRef = useRef(null); + useEffect(() => { + previousFocusRef.current = document.activeElement as HTMLElement | null; + return () => { + previousFocusRef.current?.focus(); + }; + }, []); + return (