fix: ensure exact tag matching with enter key behavior refinement (#7387)
Co-authored-by: Peng Xiao <pengxiao@outlook.com>
This commit is contained in:
@@ -197,7 +197,8 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => {
|
|||||||
[setOpen, setSelectedTagIds]
|
[setOpen, setSelectedTagIds]
|
||||||
);
|
);
|
||||||
|
|
||||||
const exactMatch = useLiveData(tagList.tagByTagValue$(inputValue));
|
const match = useLiveData(tagList.tagByTagValue$(inputValue));
|
||||||
|
const exactMatch = useLiveData(tagList.excactTagByValue$(inputValue));
|
||||||
|
|
||||||
const filteredTags = useLiveData(
|
const filteredTags = useLiveData(
|
||||||
inputValue ? tagList.filterTagsByName$(inputValue) : tagList.tags$
|
inputValue ? tagList.filterTagsByName$(inputValue) : tagList.tags$
|
||||||
@@ -266,7 +267,7 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => {
|
|||||||
tags.find(tag => tag.id === lastTagId)?.untag(pageId);
|
tags.find(tag => tag.id === lastTagId)?.untag(pageId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[exactMatch, inputValue, onAddTag, onCreateTag, pageId, tagIds, tags]
|
[inputValue, tagIds, exactMatch, onAddTag, onCreateTag, tags, pageId]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -320,7 +321,7 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{exactMatch || !inputValue ? null : (
|
{match || !inputValue ? null : (
|
||||||
<div
|
<div
|
||||||
data-testid="tag-selector-item"
|
data-testid="tag-selector-item"
|
||||||
className={styles.tagSelectorItem}
|
className={styles.tagSelectorItem}
|
||||||
|
|||||||
@@ -63,6 +63,12 @@ export class TagList extends Entity {
|
|||||||
return trimmedValue.includes(trimmedQuery);
|
return trimmedValue.includes(trimmedQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private findfn(value: string, query?: string) {
|
||||||
|
const trimmedTagValue = query?.trim().toLowerCase();
|
||||||
|
const trimmedInputValue = value.trim().toLowerCase();
|
||||||
|
return trimmedTagValue === trimmedInputValue;
|
||||||
|
}
|
||||||
|
|
||||||
filterTagsByName$(name: string) {
|
filterTagsByName$(name: string) {
|
||||||
return LiveData.computed(get => {
|
return LiveData.computed(get => {
|
||||||
return get(this.tags$).filter(tag =>
|
return get(this.tags$).filter(tag =>
|
||||||
@@ -76,4 +82,10 @@ export class TagList extends Entity {
|
|||||||
return get(this.tags$).find(tag => this.filterFn(get(tag.value$), value));
|
return get(this.tags$).find(tag => this.filterFn(get(tag.value$), value));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
excactTagByValue$(value: string) {
|
||||||
|
return LiveData.computed(get => {
|
||||||
|
return get(this.tags$).find(tag => this.findfn(get(tag.value$), value));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user