diff --git a/packages/circuit-ui/components/DateInput/components/Dialog.tsx b/packages/circuit-ui/components/DateInput/components/Dialog.tsx index 2cf5d671e2..a483fe5114 100644 --- a/packages/circuit-ui/components/DateInput/components/Dialog.tsx +++ b/packages/circuit-ui/components/DateInput/components/Dialog.tsx @@ -50,7 +50,11 @@ export const Dialog = forwardRef( const lastFocusedElementRef = useRef(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;