From 50dcce891b645819b4d732969fade7d714c98655 Mon Sep 17 00:00:00 2001 From: JimmFly <447268514@qq.com> Date: Mon, 27 May 2024 08:28:12 +0000 Subject: [PATCH] fix(core): clear input value after selecting a tag in page info (#7076) close AFF-1140 --- .../page-properties/tags-inline-editor.tsx | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/frontend/core/src/components/affine/page-properties/tags-inline-editor.tsx b/packages/frontend/core/src/components/affine/page-properties/tags-inline-editor.tsx index f3ff0efd75d2d..3fc5cdf006c96 100644 --- a/packages/frontend/core/src/components/affine/page-properties/tags-inline-editor.tsx +++ b/packages/frontend/core/src/components/affine/page-properties/tags-inline-editor.tsx @@ -8,7 +8,7 @@ import { DeleteIcon, MoreHorizontalIcon, TagsIcon } from '@blocksuite/icons'; import { useLiveData, useService } from '@toeverything/infra'; import clsx from 'clsx'; import type { HTMLAttributes, PropsWithChildren } from 'react'; -import { useCallback, useMemo, useReducer, useState } from 'react'; +import { useCallback, useMemo, useReducer, useRef, useState } from 'react'; import { TagItem, TempTagItem } from '../../page-list'; import { tagColors } from './common'; @@ -23,12 +23,15 @@ interface TagsEditorProps { interface InlineTagsListProps extends Omit, 'onChange'>, - Omit {} + Omit { + onRemove?: () => void; +} const InlineTagsList = ({ pageId, readonly, children, + onRemove, }: PropsWithChildren) => { const tagList = useService(TagService).tagList; const tags = useLiveData(tagList.tags$); @@ -45,6 +48,7 @@ const InlineTagsList = ({ ? undefined : () => { tag.untag(pageId); + onRemove?.(); }; return ( { const [inputValue, setInputValue] = useState(''); const [open, setOpen] = useState(false); const [selectedTagIds, setSelectedTagIds] = useState([]); + const inputRef = useRef(null); const handleCloseModal = useCallback( (open: boolean) => { @@ -214,6 +219,10 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => { [pageId, tagIds, tags] ); + const focusInput = useCallback(() => { + inputRef.current?.focus(); + }, []); + const [nextColor, rotateNextColor] = useReducer( color => { const idx = tagColors.findIndex(c => c[1] === color); @@ -234,6 +243,15 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => { [nextColor, pageId, tagList] ); + const onSelectTag = useCallback( + (id: string) => { + onAddTag(id); + setInputValue(''); + focusInput(); + }, + [focusInput, onAddTag] + ); + const onInputKeyDown = useCallback( (e: React.KeyboardEvent) => { if (e.key === 'Enter') { @@ -254,8 +272,13 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => { return (
- + { data-tag-id={tag.id} data-tag-value={tag.value$} onClick={() => { - onAddTag(tag.id); + onSelectTag(tag.id); }} >