mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 09:30:01 +08:00
@@ -95,9 +95,15 @@ export const TagsEditor = ({
|
|||||||
|
|
||||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const onInputChange = useCallback((value: string) => {
|
const onInputChange = useCallback(
|
||||||
setInputValue(value);
|
(value: string) => {
|
||||||
}, []);
|
setInputValue(value);
|
||||||
|
if (value.length > 0) {
|
||||||
|
setFocusedInlineIndex(selectedTags.length);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[selectedTags.length]
|
||||||
|
);
|
||||||
|
|
||||||
const onToggleTag = useCallback(
|
const onToggleTag = useCallback(
|
||||||
(id: string) => {
|
(id: string) => {
|
||||||
@@ -160,7 +166,11 @@ export const TagsEditor = ({
|
|||||||
|
|
||||||
const onInputKeyDown = useCallback(
|
const onInputKeyDown = useCallback(
|
||||||
(e: KeyboardEvent<HTMLInputElement>) => {
|
(e: KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (e.key === 'Backspace' && inputValue === '' && selectedTags.length) {
|
if (e.key === 'Backspace') {
|
||||||
|
if (inputValue.length > 0 || selectedTags.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
const index =
|
const index =
|
||||||
safeInlineFocusedIndex < 0 ||
|
safeInlineFocusedIndex < 0 ||
|
||||||
safeInlineFocusedIndex >= selectedTags.length
|
safeInlineFocusedIndex >= selectedTags.length
|
||||||
@@ -186,6 +196,9 @@ export const TagsEditor = ({
|
|||||||
// reset inline focus
|
// reset inline focus
|
||||||
setFocusedInlineIndex(selectedTags.length + 1);
|
setFocusedInlineIndex(selectedTags.length + 1);
|
||||||
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
||||||
|
if (inputValue.length > 0 || selectedTags.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const newItemToFocus =
|
const newItemToFocus =
|
||||||
e.key === 'ArrowLeft'
|
e.key === 'ArrowLeft'
|
||||||
? safeInlineFocusedIndex - 1
|
? safeInlineFocusedIndex - 1
|
||||||
|
|||||||
Reference in New Issue
Block a user