feature/IO-3603-Production-Board-Note-Autofocus - Fix

This commit is contained in:
Dave
2026-03-09 12:59:00 -04:00
parent a873a2573a
commit 8d00fc29d1
2 changed files with 26 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ export default function ProductionListColumnComment({ record, usePortal = false
const [note, setNote] = useState(record.comment || ""); const [note, setNote] = useState(record.comment || "");
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const textAreaRef = useRef(null); const textAreaRef = useRef(null);
const rafIdRef = useRef(null);
const [updateAlert] = useMutation(UPDATE_JOB); const [updateAlert] = useMutation(UPDATE_JOB);
@@ -37,14 +38,21 @@ export default function ProductionListColumnComment({ record, usePortal = false
}; };
const handleOpenChange = (flag) => { const handleOpenChange = (flag) => {
if (rafIdRef.current) {
cancelAnimationFrame(rafIdRef.current);
rafIdRef.current = null;
}
setOpen(flag); setOpen(flag);
if (flag) { if (flag) {
setNote(record.comment || ""); setNote(record.comment || "");
requestAnimationFrame(() => { rafIdRef.current = requestAnimationFrame(() => {
try { rafIdRef.current = null;
textAreaRef.current?.focus?.({ preventScroll: true }); if (textAreaRef.current?.focus) {
} catch { try {
textAreaRef.current?.focus?.(); textAreaRef.current.focus({ preventScroll: true });
} catch {
textAreaRef.current.focus();
}
} }
}); });
} }

View File

@@ -21,6 +21,7 @@ function ProductionListColumnProductionNote({ record, setNoteUpsertContext, useP
const [note, setNote] = useState(record.production_vars?.note || ""); const [note, setNote] = useState(record.production_vars?.note || "");
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const textAreaRef = useRef(null); const textAreaRef = useRef(null);
const rafIdRef = useRef(null);
const [updateAlert] = useMutation(UPDATE_JOB); const [updateAlert] = useMutation(UPDATE_JOB);
@@ -53,14 +54,21 @@ function ProductionListColumnProductionNote({ record, setNoteUpsertContext, useP
const handleOpenChange = useCallback( const handleOpenChange = useCallback(
(flag) => { (flag) => {
if (rafIdRef.current) {
cancelAnimationFrame(rafIdRef.current);
rafIdRef.current = null;
}
setOpen(flag); setOpen(flag);
if (flag) { if (flag) {
setNote(record.production_vars?.note || ""); setNote(record.production_vars?.note || "");
requestAnimationFrame(() => { rafIdRef.current = requestAnimationFrame(() => {
try { rafIdRef.current = null;
textAreaRef.current?.focus?.({ preventScroll: true }); if (textAreaRef.current?.focus) {
} catch { try {
textAreaRef.current?.focus?.(); textAreaRef.current.focus({ preventScroll: true });
} catch {
textAreaRef.current.focus();
}
} }
}); });
} }