mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-11-20 17:21:24 +03:00
F: Return focus on dialog close
This commit is contained in:
parent
c9bc3401b0
commit
f08ee8e00f
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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} />
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user