From d6f1cc3730a6ff01cb844637406a411df01728db Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Wed, 26 May 2021 17:38:20 -0300 Subject: [PATCH] feat: focus last tag when pressing backspace on input --- .../javascripts/components/AutocompleteTagInput.tsx | 9 ++++++++- app/assets/javascripts/components/NoteTags.tsx | 9 +++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/components/AutocompleteTagInput.tsx b/app/assets/javascripts/components/AutocompleteTagInput.tsx index 9ae7e7ca5..0150834d1 100644 --- a/app/assets/javascripts/components/AutocompleteTagInput.tsx +++ b/app/assets/javascripts/components/AutocompleteTagInput.tsx @@ -1,6 +1,6 @@ import { WebApplication } from '@/ui_models/application'; import { SNTag } from '@standardnotes/snjs'; -import { FunctionalComponent } from 'preact'; +import { FunctionalComponent, RefObject } from 'preact'; import { useRef, useState } from 'preact/hooks'; import { Icon } from './Icon'; import { Disclosure, DisclosurePanel } from '@reach/disclosure'; @@ -10,11 +10,13 @@ import { AppState } from '@/ui_models/app_state'; type Props = { application: WebApplication; appState: AppState; + lastTagRef: RefObject; }; export const AutocompleteTagInput: FunctionalComponent = ({ application, appState, + lastTagRef, }) => { const [searchQuery, setSearchQuery] = useState(''); const [dropdownVisible, setDropdownVisible] = useState(false); @@ -92,6 +94,11 @@ export const AutocompleteTagInput: FunctionalComponent = ({ type="text" onBlur={closeOnBlur} onFocus={showDropdown} + onKeyUp={(event) => { + if (event.key === 'Backspace') { + lastTagRef.current?.focus(); + } + }} /> {dropdownVisible && ( { + const { activeNoteTags } = appState.notes; + const lastTagRef = useRef(); + return (
- {appState.notes.activeNoteTags.map((tag) => ( + {activeNoteTags.map((tag, index) => ( ))} - +
); });