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,
|
||||
}: CommentMentionComposerProps) {
|
||||
const inputRef = useRef<HTMLTextAreaElement | HTMLInputElement>(null);
|
||||
const valueRef = useRef(value);
|
||||
valueRef.current = value;
|
||||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
||||
const [cursor, setCursor] = useState(0);
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
|
|
@ -59,12 +61,14 @@ export function CommentMentionComposer({
|
|||
return;
|
||||
}
|
||||
|
||||
const nextCursor = element.selectionStart ?? value.length;
|
||||
const currentValue = valueRef.current;
|
||||
const nextCursor = element.selectionStart ?? currentValue.length;
|
||||
setCursor(nextCursor);
|
||||
setMenuOpen(Boolean(findActiveMentionQuery(value, nextCursor)));
|
||||
}, [value]);
|
||||
setMenuOpen(Boolean(findActiveMentionQuery(currentValue, nextCursor)));
|
||||
}, []);
|
||||
|
||||
const handleChange = (nextValue: string) => {
|
||||
valueRef.current = nextValue;
|
||||
onChange(nextValue);
|
||||
requestAnimationFrame(syncCursor);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue