From 5c3c74b32e49adf630cdb496c3bff96d4e9a3cd5 Mon Sep 17 00:00:00 2001 From: Anika Raemer Date: Sun, 14 Sep 2025 14:24:35 +0200 Subject: [PATCH] fix search field behavior --- frontend/src/App.css | 10 +++++----- .../src/components/basics/SearchField.tsx | 20 +++++++++++-------- .../src/components/recipes/RecipeListItem.tsx | 2 +- .../src/components/recipes/RecipeListPage.tsx | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/frontend/src/App.css b/frontend/src/App.css index 79dc4f9..0877dae 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -28,6 +28,10 @@ @apply font-semibold mb-2 mt-4; } + .label { + @apply text-gray-600 + } + /* buttons */ .primary-button { @apply bg-blue-300 px-4 py-2 shadow-md rounded-lg hover:bg-blue-400 text-gray-600 whitespace-nowrap @@ -41,15 +45,11 @@ @apply bg-gray-600 hover:bg-gray-800 text-white shadow-md rounded px-4 py-2 whitespace-nowrap } - /* input field */ + /* input fields like input and textarea */ .input-field { @apply p-2 w-full border rounded-md placeholder-gray-400 border-gray-600 hover:border-blue-600 transition-colors text-gray-600 focus:outline-none focus:border-blue-800; } - .text-area { - @apply border p-2 w-full mb-2 rounded placeholder-gray-400; - } - /* groups */ .button-group{ @apply flex gap-4 mt-4; diff --git a/frontend/src/components/basics/SearchField.tsx b/frontend/src/components/basics/SearchField.tsx index acce6a7..3f60b41 100644 --- a/frontend/src/components/basics/SearchField.tsx +++ b/frontend/src/components/basics/SearchField.tsx @@ -1,8 +1,9 @@ +import { useState } from "react"; + /** * Custom search field component including a clear search functionality */ type SearchFieldProps = { - searchString : string onSearchStringChanged: (searchString : string) => void } @@ -10,10 +11,13 @@ type SearchFieldProps = { * @param SearchFieldProps consisting of an initial searchString and an onSearchStringChanged handler * @returns Custom search field component */ -export default function SearchField({searchString, onSearchStringChanged} : SearchFieldProps){ - const setSearchString = (newSearchString : string) => { - searchString = newSearchString; - onSearchStringChanged(searchString) +export default function SearchField({onSearchStringChanged} : SearchFieldProps){ + const [currentSearchString, setCurrentSearchString] = useState("") + + const changeSearchString = (newSearchString : string) => { + console.log(newSearchString); + setCurrentSearchString(newSearchString); + onSearchStringChanged(newSearchString) } return ( @@ -26,15 +30,15 @@ export default function SearchField({searchString, onSearchStringChanged} : Sear className="input-field pl-10 pr-10" type="text" placeholder="Search" - value={searchString} - onChange={ e => setSearchString(e.target.value) } + value={currentSearchString} + onChange={ e => changeSearchString(e.target.value) } /> {/* Right icon: X Clears search string on click */}