Skip to content

Commit f0c247f

Browse files
authored
fix: prevent input from losing focus after first keystroke
Refs: CO-3372 (#621)
1 parent b57d9ff commit f0c247f

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/components/feedback/CustomModal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const CustomModal = React.forwardRef<HTMLDivElement, CustomModalProps>(function
8181
const modalContentRef = useRef<HTMLDivElement>(null);
8282
const startSentinelRef = useRef<HTMLDivElement>(null);
8383
const endSentinelRef = useRef<HTMLDivElement>(null);
84+
const focusModalContentRef = useRef(focusModalContent);
8485

8586
const onBackdropClick = useCallback(
8687
(e: KeyboardEvent | React.MouseEvent<HTMLDivElement>) => {
@@ -147,7 +148,7 @@ const CustomModal = React.forwardRef<HTMLDivElement, CustomModalProps>(function
147148
const endSentinelRefSave = endSentinelRef.current;
148149

149150
if (open) {
150-
if (focusModalContent) {
151+
if (focusModalContentRef.current) {
151152
modalContentRef.current && modalContentRef.current.focus();
152153
}
153154
startSentinelRefSave && startSentinelRefSave.addEventListener('focus', onStartSentinelFocus);
@@ -160,7 +161,7 @@ const CustomModal = React.forwardRef<HTMLDivElement, CustomModalProps>(function
160161
endSentinelRefSave && endSentinelRefSave.removeEventListener('focus', onEndSentinelFocus);
161162
open && focusedElement && focusedElement.focus();
162163
};
163-
}, [open, onStartSentinelFocus, onEndSentinelFocus, windowObj, focusModalContent]);
164+
}, [open, onStartSentinelFocus, onEndSentinelFocus, windowObj]);
164165

165166
useEffect(() => {
166167
// delay the open of the modal after the show of the portal

0 commit comments

Comments
 (0)