From 41236d3483534704833ca058a73d3d3f79e854ed Mon Sep 17 00:00:00 2001 From: Dominik Danielewicz Date: Wed, 20 Mar 2024 19:01:04 +0100 Subject: [PATCH] feat: optional search clear text --- src/components/SearchBar.tsx | 11 +++++++---- src/contexts/KeyboardContext.ts | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/SearchBar.tsx b/src/components/SearchBar.tsx index e52381c..173d5e7 100644 --- a/src/components/SearchBar.tsx +++ b/src/components/SearchBar.tsx @@ -7,6 +7,7 @@ export const SearchBar = () => { const { searchPhrase, setSearchPhrase, + hideSearchBarClearIcon, translation, setActiveCategoryIndex, renderList, @@ -19,11 +20,11 @@ export const SearchBar = () => { } = React.useContext(KeyboardContext) const inputRef = React.useRef(null) - const handleSearch = async (text: string) => { + const handleSearch = (text: string) => { setSearchPhrase(text) if (text === '') { - await setActiveCategoryIndex(0) + setActiveCategoryIndex(0) setShouldAnimateScroll(enableCategoryChangeAnimation) return @@ -38,8 +39,10 @@ export const SearchBar = () => { const clearPhrase = () => { setSearchPhrase('') clearEmojiTonesData() - inputRef.current?.blur() setActiveCategoryIndex(0) + setTimeout(() => { + inputRef.current?.blur() + }, 0) } return ( @@ -59,7 +62,7 @@ export const SearchBar = () => { onTouchEndCapture={clearEmojiTonesData} placeholderTextColor={theme.search.placeholder} /> - {!!searchPhrase && ( + {!hideSearchBarClearIcon && !!searchPhrase && ( void disableSafeArea?: boolean @@ -163,6 +164,7 @@ export const defaultKeyboardContext: Required & { enableRecentlyUsed: false, categoryPosition: 'floating', enableSearchBar: false, + hideSearchBarClearIcon: false, categoryOrder: [...CATEGORIES], onRequestClose: () => {}, disableSafeArea: false,