From 552cbca3b3cc24495947cbee9cb10fb0481a5030 Mon Sep 17 00:00:00 2001 From: Varun Raj Date: Tue, 25 Mar 2025 21:29:35 +0530 Subject: [PATCH] refactor: update autocomplete behavior and labels - Changed the label for creating a new person in the PersonItem component from "Merge with this person" to "Create". - Removed unnecessary focus management code in the Autocomplete component to simplify the input behavior. - Cleaned up comments related to focus handling after selection and creation of new options. --- src/components/people/PersonItem.tsx | 2 +- src/components/ui/autocomplete.tsx | 33 +--------------------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/src/components/people/PersonItem.tsx b/src/components/people/PersonItem.tsx index c8cdba1..155dde4 100644 --- a/src/components/people/PersonItem.tsx +++ b/src/components/people/PersonItem.tsx @@ -152,7 +152,7 @@ export default function PersonItem({ person, onRemove }: IProps) { mergeDialogRef.current?.open(); selectedPerson.current = value; }} - createNewLabel="Merge with this person" + createNewLabel="Create" disabled={loading} onCreateNew={(value) => { handleEdit(); diff --git a/src/components/ui/autocomplete.tsx b/src/components/ui/autocomplete.tsx index 5fa48f3..25ba072 100644 --- a/src/components/ui/autocomplete.tsx +++ b/src/components/ui/autocomplete.tsx @@ -62,12 +62,6 @@ const Autocomplete = React.forwardRef( if (containerRef.current && !containerRef.current.contains(event.target as Node)) { setOpen(false) setSelectedIndex(-1) - // Don't blur the input when clicking outside with a small delay - setTimeout(() => { - if (inputRef.current) { - inputRef.current.focus() - } - }, 0) } } @@ -146,22 +140,10 @@ const Autocomplete = React.forwardRef( onOptionSelect(option) setOpen(false) setSelectedIndex(-1) - // Keep focus on input after selection with a small delay - setTimeout(() => { - if (inputRef.current) { - inputRef.current.focus() - } - }, 0) } else if (showCreateNew && selectedIndex === filteredOptions.length) { onCreateNew(inputValue.trim()) setOpen(false) setSelectedIndex(-1) - // Keep focus on input after creating new with a small delay - setTimeout(() => { - if (inputRef.current) { - inputRef.current.focus() - } - }, 0) } break case 'Escape': @@ -190,9 +172,8 @@ const Autocomplete = React.forwardRef( } }} value={inputValue} - onFocus={(e) => { + onFocus={() => { setOpen(true) - // containerRef.current?.focus() }} onKeyDown={handleKeyDown} placeholder={placeholder} @@ -224,12 +205,6 @@ const Autocomplete = React.forwardRef( onOptionSelect(option) setOpen(false) setSelectedIndex(-1) - // Keep focus on input after selection with a small delay - setTimeout(() => { - if (inputRef.current) { - inputRef.current.focus() - } - }, 0) }} > {option.imageUrl && ( @@ -250,12 +225,6 @@ const Autocomplete = React.forwardRef( onCreateNew(inputValue.trim()) setOpen(false) setSelectedIndex(-1) - // Keep focus on input after creating new with a small delay - setTimeout(() => { - if (inputRef.current) { - inputRef.current.focus() - } - }, 0) }} > {createNewLabel} "{inputValue.trim()}"