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.
This commit is contained in:
Varun Raj committed 2025-03-25 21:29:35 +05:30
1 parent 57c9bd2070
commit 552cbca3b3
2 files changed
+2 -33

No files matched your search

+1 -1
View File
@@ -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();
+1 -32
View File
@@ -62,12 +62,6 @@ const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(
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<HTMLInputElement, AutocompleteProps>(
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<HTMLInputElement, AutocompleteProps>(
}
}}
value={inputValue}
onFocus={(e) => {
onFocus={() => {
setOpen(true)
// containerRef.current?.focus()
}}
onKeyDown={handleKeyDown}
placeholder={placeholder}
@@ -224,12 +205,6 @@ const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(
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<HTMLInputElement, AutocompleteProps>(
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} &quot;{inputValue.trim()}&quot;