F: Return focus on dialog close

This commit is contained in:
Ivan 2025-11-20 13:18:26 +03:00
parent c9bc3401b0
commit f08ee8e00f
2 changed files with 18 additions and 0 deletions

View File

@ -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<ModalFormProps>) {
const hideDialog = useDialogsStore(state => state.hideDialog);
const previousFocusRef = useRef<HTMLElement | null>(null);
useEffect(() => {
previousFocusRef.current = document.activeElement as HTMLElement | null;
return () => {
previousFocusRef.current?.focus();
};
}, []);
function handleCancel() {
onCancel?.();
hideDialog();

View File

@ -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<HTMLElement | null>(null);
useEffect(() => {
previousFocusRef.current = document.activeElement as HTMLElement | null;
return () => {
previousFocusRef.current?.focus();
};
}, []);
return (
<div className='cc-modal-wrapper'>
<ModalBackdrop onHide={hideDialog} />