IO-3603 Production Board Note Autofocus
Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import Icon from "@ant-design/icons";
|
||||
import { useMutation } from "@apollo/client/react";
|
||||
import { Button, Input, Popover, Tooltip } from "antd";
|
||||
import { useState } from "react";
|
||||
import { useState, useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FaRegStickyNote } from "react-icons/fa";
|
||||
import { UPDATE_JOB } from "../../graphql/jobs.queries";
|
||||
@@ -9,10 +9,9 @@ import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
|
||||
export default function ProductionListColumnComment({ record, usePortal = false }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [note, setNote] = useState(record.comment || "");
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const textAreaRef = useRef(null);
|
||||
|
||||
const [updateAlert] = useMutation(UPDATE_JOB);
|
||||
|
||||
@@ -39,22 +38,27 @@ export default function ProductionListColumnComment({ record, usePortal = false
|
||||
|
||||
const handleOpenChange = (flag) => {
|
||||
setOpen(flag);
|
||||
if (flag) setNote(record.comment || "");
|
||||
if (flag) {
|
||||
setNote(record.comment || "");
|
||||
requestAnimationFrame(() => {
|
||||
try {
|
||||
textAreaRef.current?.focus?.({ preventScroll: true });
|
||||
} catch {
|
||||
textAreaRef.current?.focus?.();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const content = (
|
||||
<div
|
||||
style={{ width: "30em" }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onPointerDown={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div style={{ width: "30em" }} onClick={(e) => e.stopPropagation()} onPointerDown={(e) => e.stopPropagation()}>
|
||||
<Input.TextArea
|
||||
id={`job-comment-${record.id}`}
|
||||
name="comment"
|
||||
rows={5}
|
||||
value={note}
|
||||
onChange={handleChange}
|
||||
autoFocus
|
||||
ref={textAreaRef}
|
||||
allowClear
|
||||
style={{ marginBottom: "1em" }}
|
||||
/>
|
||||
@@ -73,7 +77,7 @@ export default function ProductionListColumnComment({ record, usePortal = false
|
||||
content={content}
|
||||
trigger="click"
|
||||
destroyOnHidden
|
||||
styles={{ body: { padding: '12px' } }}
|
||||
styles={{ body: { padding: "12px" } }}
|
||||
{...(usePortal ? { getPopupContainer: (trigger) => trigger.parentElement || document.body } : {})}
|
||||
>
|
||||
<div
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Icon from "@ant-design/icons";
|
||||
import { useMutation } from "@apollo/client/react";
|
||||
import { Button, Input, Popover, Space } from "antd";
|
||||
import { useCallback, useState } from "react";
|
||||
import { useCallback, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FaRegStickyNote } from "react-icons/fa";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
@@ -20,6 +20,7 @@ function ProductionListColumnProductionNote({ record, setNoteUpsertContext, useP
|
||||
const { t } = useTranslation();
|
||||
const [note, setNote] = useState(record.production_vars?.note || "");
|
||||
const [open, setOpen] = useState(false);
|
||||
const textAreaRef = useRef(null);
|
||||
|
||||
const [updateAlert] = useMutation(UPDATE_JOB);
|
||||
|
||||
@@ -53,24 +54,29 @@ function ProductionListColumnProductionNote({ record, setNoteUpsertContext, useP
|
||||
const handleOpenChange = useCallback(
|
||||
(flag) => {
|
||||
setOpen(flag);
|
||||
if (flag) setNote(record.production_vars?.note || "");
|
||||
if (flag) {
|
||||
setNote(record.production_vars?.note || "");
|
||||
requestAnimationFrame(() => {
|
||||
try {
|
||||
textAreaRef.current?.focus?.({ preventScroll: true });
|
||||
} catch {
|
||||
textAreaRef.current?.focus?.();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
[record]
|
||||
);
|
||||
|
||||
const content = (
|
||||
<div
|
||||
style={{ width: "30em" }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onPointerDown={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div style={{ width: "30em" }} onClick={(e) => e.stopPropagation()} onPointerDown={(e) => e.stopPropagation()}>
|
||||
<Input.TextArea
|
||||
id={`job-production-note-${record.id}`}
|
||||
name="production_note"
|
||||
rows={5}
|
||||
value={note}
|
||||
onChange={handleChange}
|
||||
autoFocus
|
||||
ref={textAreaRef}
|
||||
allowClear
|
||||
style={{ marginBottom: "1em" }}
|
||||
/>
|
||||
@@ -102,7 +108,7 @@ function ProductionListColumnProductionNote({ record, setNoteUpsertContext, useP
|
||||
content={content}
|
||||
trigger="click"
|
||||
destroyOnHidden
|
||||
styles={{ body: { padding: '12px' } }}
|
||||
styles={{ body: { padding: "12px" } }}
|
||||
{...(usePortal ? { getPopupContainer: (trigger) => trigger.parentElement || document.body } : {})}
|
||||
>
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user