From 4720456d63c0b29854b68d73a4a46323d9b27aec Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Tue, 28 Oct 2025 11:50:25 +0500 Subject: [PATCH] mobile: add clear button to search on mobile --- apps/mobile/app/screens/search/search-bar.tsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/mobile/app/screens/search/search-bar.tsx b/apps/mobile/app/screens/search/search-bar.tsx index 6bed797a6..b18e8d7d4 100644 --- a/apps/mobile/app/screens/search/search-bar.tsx +++ b/apps/mobile/app/screens/search/search-bar.tsx @@ -19,7 +19,7 @@ along with this program. If not, see . import { strings } from "@notesnook/intl"; import { useThemeColors } from "@notesnook/theme"; -import React, { useRef } from "react"; +import React, { useRef, useState } from "react"; import { View } from "react-native"; import { TextInput } from "react-native-gesture-handler"; import { IconButton } from "../../components/ui/icon-button"; @@ -36,6 +36,7 @@ export const SearchBar = ({ onChangeText: (value: string) => void; loading?: boolean; }) => { + const [clearButton, setClearButton] = useState(false); const selectionMode = useSelectionStore((state) => state.selectionMode); const isFocused = useNavigationStore( (state) => state.focusedRouteId === "Search" @@ -45,6 +46,7 @@ export const SearchBar = ({ const inputRef = useRef(null); const _onChangeText = (value: string) => { onChangeText(value); + setClearButton(!!value); }; return selectionMode && isFocused ? null : ( @@ -100,6 +102,22 @@ export const SearchBar = ({ autoCorrect={false} placeholderTextColor={colors.primary.placeholder} /> + + {clearButton ? ( + { + inputRef.current?.clear(); + onChangeText(""); + setClearButton(false); + }} + color={colors.primary.paragraph} + type="plain" + /> + ) : null} );