refactor: update the goal node to have a description for plans that need to be checked, and correctly give the value to the CB.
ref: N25B-412
This commit is contained in:
75
src/components/MultilineTextField.tsx
Normal file
75
src/components/MultilineTextField.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import styles from "./TextField.module.css";
|
||||
|
||||
export function MultilineTextField({
|
||||
value = "",
|
||||
setValue,
|
||||
placeholder,
|
||||
className,
|
||||
id,
|
||||
ariaLabel,
|
||||
invalid = false,
|
||||
minRows = 3,
|
||||
}: {
|
||||
value: string;
|
||||
setValue: (value: string) => void;
|
||||
placeholder?: string;
|
||||
className?: string;
|
||||
id?: string;
|
||||
ariaLabel?: string;
|
||||
invalid?: boolean;
|
||||
minRows?: number;
|
||||
}) {
|
||||
const [readOnly, setReadOnly] = useState(true);
|
||||
const [inputValue, setInputValue] = useState(value);
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setInputValue(value);
|
||||
}, [value]);
|
||||
|
||||
// Auto-grow logic
|
||||
useEffect(() => {
|
||||
const el = textareaRef.current;
|
||||
if (!el) return;
|
||||
|
||||
el.style.height = "auto";
|
||||
el.style.height = `${el.scrollHeight}px`;
|
||||
}, [inputValue]);
|
||||
|
||||
const onCommit = () => {
|
||||
setReadOnly(true);
|
||||
setValue(inputValue);
|
||||
};
|
||||
|
||||
const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
||||
e.preventDefault();
|
||||
(e.target as HTMLTextAreaElement).blur();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
rows={minRows}
|
||||
placeholder={placeholder}
|
||||
value={inputValue}
|
||||
onChange={(e) => setInputValue(e.target.value)}
|
||||
onFocus={() => setReadOnly(false)}
|
||||
onBlur={onCommit}
|
||||
onKeyDown={onKeyDown}
|
||||
readOnly={readOnly}
|
||||
id={id}
|
||||
aria-label={ariaLabel}
|
||||
className={`
|
||||
${readOnly ? "drag" : "nodrag"}
|
||||
flex-1
|
||||
${styles.textField}
|
||||
${styles.multiline}
|
||||
${invalid ? styles.invalid : ""}
|
||||
${className ?? ""}
|
||||
`}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user