diff --git a/packages/nc-gui/components/smartsheet/expanded-form/Comments.vue b/packages/nc-gui/components/smartsheet/expanded-form/Comments.vue index f144978060..4fd776cfd7 100644 --- a/packages/nc-gui/components/smartsheet/expanded-form/Comments.vue +++ b/packages/nc-gui/components/smartsheet/expanded-form/Comments.vue @@ -29,8 +29,19 @@ const editLog = ref() const isEditing = ref(false) -const commentInputDomRef = ref() - +const isCommentMode = ref(false) + +const focusCommentInput: VNodeRef = (el) => { + if (!isExpandedFormLoading.value && (isCommentMode.value || isExpandedFormCommentMode.value) && !isEditing.value) { + if (isExpandedFormCommentMode.value) { + setTimeout(() => { + isExpandedFormCommentMode.value = false + }, 400) + } + return (el as HTMLInputElement)?.focus() + } + return el +} const focusInput: VNodeRef = (el) => (el as HTMLInputElement)?.focus() function onKeyDown(event: KeyboardEvent) { @@ -55,6 +66,9 @@ function onKeyEsc(event: KeyboardEvent) { async function onEditComment() { if (!isEditing.value || !editLog.value) return + + isCommentMode.value = true + await updateComment(editLog.value.id!, { description: editLog.value.description, }) @@ -106,6 +120,7 @@ const isSaving = ref(false) const saveComment = async () => { if (isSaving.value) return + isCommentMode.value = true isSaving.value = true try { @@ -117,10 +132,6 @@ const saveComment = async () => { } finally { isSaving.value = false } - - nextTick(() => { - commentInputDomRef.value?.focus() - }) } watch(commentsWrapperEl, () => { @@ -132,15 +143,6 @@ const onClickAudit = () => { tab.value = 'audits' } - -watch(commentInputDomRef, () => { - if (commentInputDomRef.value && isExpandedFormCommentMode.value) { - setTimeout(() => { - commentInputDomRef.value?.focus() - isExpandedFormCommentMode.value = false - }, 400) - } -})