mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 10:51:02 +01:00
feat: add backspace functionality to remove last search term in SearchBar component
This commit is contained in:
@@ -29,6 +29,14 @@ const SearchBar = ({
|
||||
return () => document.removeEventListener('keydown', handleKeyDown);
|
||||
}, [onClearTerms]);
|
||||
|
||||
const handleKeyDown = e => {
|
||||
// Handle backspace when input is empty and there are search terms
|
||||
if (e.key === 'Backspace' && !currentInput && searchTerms.length > 0) {
|
||||
e.preventDefault();
|
||||
onRemoveTerm(searchTerms[searchTerms.length - 1]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyPress = e => {
|
||||
if (requireEnter && e.key === 'Enter' && currentInput.trim()) {
|
||||
onAddTerm(currentInput);
|
||||
@@ -91,6 +99,7 @@ const SearchBar = ({
|
||||
value={currentInput}
|
||||
onChange={e => onInputChange(e.target.value)}
|
||||
onKeyPress={handleKeyPress}
|
||||
onKeyDown={handleKeyDown}
|
||||
onFocus={() => setIsFocused(true)}
|
||||
onBlur={() => setIsFocused(false)}
|
||||
placeholder={
|
||||
|
||||
Reference in New Issue
Block a user