Skip to content

Commit

Permalink
add explanatory comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sirineJ committed Nov 12, 2024
1 parent 8dff858 commit 65ccb51
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export const Dialog = forwardRef<HTMLDialogElement, DialogProps>(
const lastFocusedElementRef = useRef<Element | null>(null);

const handleClickOutside = useCallback(
// store it as the last focused element
// When the dialog first opens, we store the document's active element as the last active
// element to restore focus to it when the dialog closes.
// however, if the dialog is closed by clicking outside of it in non-modal mode,
// we don't want to restore focus to the last active element, so we override it
// with the element triggering the useClickOutside hook.
(event: Event) => {
if (event.target instanceof HTMLElement) {
lastFocusedElementRef.current = event.target;
Expand Down

0 comments on commit 65ccb51

Please sign in to comment.