fix: show autocomplete tag results only if query isn't empty
This commit is contained in:
@@ -5,6 +5,7 @@ import { AppState } from '@/ui_models/app_state';
|
||||
import { AutocompleteTagResult } from './AutocompleteTagResult';
|
||||
import { AutocompleteTagHint } from './AutocompleteTagHint';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { SNTag } from '@standardnotes/snjs';
|
||||
|
||||
type Props = {
|
||||
appState: AppState;
|
||||
@@ -41,8 +42,13 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
|
||||
|
||||
const onSearchQueryChange = (event: Event) => {
|
||||
const query = (event.target as HTMLInputElement).value;
|
||||
appState.noteTags.setAutocompleteSearchQuery(query);
|
||||
appState.noteTags.searchActiveNoteAutocompleteTags();
|
||||
|
||||
if (query === '') {
|
||||
appState.noteTags.clearAutocompleteSearch();
|
||||
} else {
|
||||
appState.noteTags.setAutocompleteSearchQuery(query);
|
||||
appState.noteTags.searchActiveNoteAutocompleteTags();
|
||||
}
|
||||
};
|
||||
|
||||
const onFormSubmit = async (event: Event) => {
|
||||
@@ -83,10 +89,6 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
|
||||
appState.noteTags.setAutocompleteInputFocused(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
appState.noteTags.searchActiveNoteAutocompleteTags();
|
||||
}, [appState.noteTags]);
|
||||
|
||||
useEffect(() => {
|
||||
if (autocompleteInputFocused) {
|
||||
inputRef.current.focus();
|
||||
@@ -120,7 +122,7 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
|
||||
onBlur={closeOnBlur}
|
||||
>
|
||||
<div className="overflow-y-auto">
|
||||
{autocompleteTagResults.map((tagResult) => (
|
||||
{autocompleteTagResults.map((tagResult: SNTag) => (
|
||||
<AutocompleteTagResult
|
||||
key={tagResult.uuid}
|
||||
appState={appState}
|
||||
|
||||
@@ -98,7 +98,7 @@ export class NoteTagsState {
|
||||
|
||||
clearAutocompleteSearch(): void {
|
||||
this.setAutocompleteSearchQuery('');
|
||||
this.searchActiveNoteAutocompleteTags();
|
||||
this.setAutocompleteTagResults([]);
|
||||
}
|
||||
|
||||
async createAndAddNewTag(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user