From b3d06b32c98cc863b7ffeaeca16c4d564f5cc299 Mon Sep 17 00:00:00 2001 From: Tony Vi Date: Mon, 14 Aug 2023 14:53:18 +0300 Subject: [PATCH] fix(CommentView): provide cancel handler for CommentForm --- src/components/CommentView/CommentView.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/CommentView/CommentView.tsx b/src/components/CommentView/CommentView.tsx index 122eb7b72..2ecffd8c6 100644 --- a/src/components/CommentView/CommentView.tsx +++ b/src/components/CommentView/CommentView.tsx @@ -152,11 +152,13 @@ export const CommentView: FC = ({ const onCommentDoubleClick = useCallback((e) => { if (e.detail === 2) { setEditMode(true); + setFocused(true); } }, []); const onCommentSubmit = useCallback( async (form: CommentSchema) => { + setEditMode(false); setBusy(true); setFocused(false); @@ -175,12 +177,22 @@ export const CommentView: FC = ({ [onSubmit, onChange, description], ); + const onCommentCancel = useCallback(() => { + setEditMode(false); + setFocused(false); + setCommentDescription({ description }); + onCancel?.(); + }, [description, onCancel]); + const dropdownItems = useMemo( () => [ { label: tr('Edit'), icon: , - onClick: () => setEditMode(true), + onClick: () => { + setEditMode(true); + setFocused(true); + }, }, { label: tr('Delete'), @@ -210,7 +222,7 @@ export const CommentView: FC = ({ autoFocus onChange={setCommentDescription} onSubmit={onCommentSubmit} - onCancel={onCancel} + onCancel={onCommentCancel} actionButton={