feat: remove tag on backspace press

This commit is contained in:
Antonella Sgarlatta
2021-05-26 17:49:09 -03:00
parent d6f1cc3730
commit 69c9247cd9
3 changed files with 25 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import { Icon } from './Icon';
import { AutocompleteTagInput } from './AutocompleteTagInput';
import { WebApplication } from '@/ui_models/application';
import { useRef } from 'preact/hooks';
import { SNTag } from '@standardnotes/snjs';
type Props = {
application: WebApplication;
@@ -15,6 +16,11 @@ const NoteTags = observer(({ application, appState }: Props) => {
const { activeNoteTags } = appState.notes;
const lastTagRef = useRef<HTMLButtonElement>();
const onTagBackspacePress = async (tag: SNTag) => {
await appState.notes.removeTagFromActiveNote(tag);
lastTagRef.current?.focus();
};
return (
<div className="flex flex-wrap">
{activeNoteTags.map((tag, index) => (
@@ -22,6 +28,11 @@ const NoteTags = observer(({ application, appState }: Props) => {
className={`bg-contrast border-0 rounded text-xs color-text p-1 flex items-center
mt-2 mr-2 cursor-pointer hover:bg-secondary-contrast focus:bg-secondary-contrast`}
ref={index === activeNoteTags.length - 1 ? lastTagRef : undefined}
onKeyUp={(event) => {
if (event.key === 'Backspace') {
onTagBackspacePress(tag);
}
}}
>
<Icon type="hashtag" className="sn-icon--small color-neutral mr-1" />
{tag.title}