mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
fix(work-orders): keep mention cursor sync on current value [SH-217]
This commit is contained in:
parent
95bd443359
commit
8783aa6e18
1 changed files with 7 additions and 3 deletions
|
|
@ -35,6 +35,8 @@ export function CommentMentionComposer({
|
||||||
onSubmit,
|
onSubmit,
|
||||||
}: CommentMentionComposerProps) {
|
}: CommentMentionComposerProps) {
|
||||||
const inputRef = useRef<HTMLTextAreaElement | HTMLInputElement>(null);
|
const inputRef = useRef<HTMLTextAreaElement | HTMLInputElement>(null);
|
||||||
|
const valueRef = useRef(value);
|
||||||
|
valueRef.current = value;
|
||||||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
||||||
const [cursor, setCursor] = useState(0);
|
const [cursor, setCursor] = useState(0);
|
||||||
const [menuOpen, setMenuOpen] = useState(false);
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
|
|
@ -59,12 +61,14 @@ export function CommentMentionComposer({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextCursor = element.selectionStart ?? value.length;
|
const currentValue = valueRef.current;
|
||||||
|
const nextCursor = element.selectionStart ?? currentValue.length;
|
||||||
setCursor(nextCursor);
|
setCursor(nextCursor);
|
||||||
setMenuOpen(Boolean(findActiveMentionQuery(value, nextCursor)));
|
setMenuOpen(Boolean(findActiveMentionQuery(currentValue, nextCursor)));
|
||||||
}, [value]);
|
}, []);
|
||||||
|
|
||||||
const handleChange = (nextValue: string) => {
|
const handleChange = (nextValue: string) => {
|
||||||
|
valueRef.current = nextValue;
|
||||||
onChange(nextValue);
|
onChange(nextValue);
|
||||||
requestAnimationFrame(syncCursor);
|
requestAnimationFrame(syncCursor);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue