) => {
- event.preventDefault(); // ikke last siden på nytt
- const search = value.trim();
- if (search && onSearch) {
- onSearch(search);
- }
+ event.preventDefault();
+ onSearch?.(value.trim());
+ };
+
+ // Tøm teksten uten å gjennomføre et søk.
+ const clearSearch = () => {
+ setValue("");
+ inputRef.current?.focus();
};
const sizeClass = size === "large" ? "search-field--large" : "";
@@ -40,7 +48,9 @@ export default function SearchField({
onSubmit={handleSubmit}
>
+
+
+ {value.length > 0 && onSearch && (
+
+ )}
+
{children}
);
diff --git a/frontend/src/components/searchfield/Searchfield.css b/frontend/src/components/searchfield/Searchfield.css
index 5d08d54..49dc99a 100644
--- a/frontend/src/components/searchfield/Searchfield.css
+++ b/frontend/src/components/searchfield/Searchfield.css
@@ -1,5 +1,9 @@
-/* SearchField – fra Figma (Components → SearchField)
- Variantene: standard (i headeren) og --large (på forsiden). */
+/* ==========================================
+ SEARCH FIELD – FIGMA-KOMPONENT
+ ========================================== */
+
+/* Grunnstruktur for søkefeltet */
+
.search-field {
display: flex;
align-items: center;
@@ -15,6 +19,7 @@
}
/* Søkeikonet: en sirkel med et skaft */
+
.search-field__icon {
position: relative;
flex-shrink: 0;
@@ -44,6 +49,8 @@
transform: rotate(45deg);
}
+/* Inputfelt */
+
.search-field__input {
flex: 1;
min-width: 0;
@@ -63,7 +70,8 @@
outline-offset: 2px;
}
-/* Liten «⌘K»-snarvei til høyre */
+/* Liten tastatursnarvei */
+
.search-field__shortcut {
padding: 2px 6px;
border: 1px solid var(--border-hairline);
@@ -72,7 +80,8 @@
color: var(--text-muted);
}
-/* Stor variant: hvit, tydelig kant og en knapp inni */
+/* Stor variant fra Figma – brukes på startsiden */
+
.search-field--large {
height: 60px;
padding: 0 8px 0 16px;
@@ -84,3 +93,52 @@
.search-field--large .search-field__input {
font-size: 1.0625rem;
}
+
+/* ==========================================
+ TØM SØKEFELT – ISSUE #151
+ ========================================== */
+
+/* Skjul nettleserens innebygde tøm-knapp */
+
+.search-field__input::-webkit-search-cancel-button {
+ -webkit-appearance: none;
+ appearance: none;
+}
+
+/* Egen tøm-knapp for desktop og mobil */
+
+.search-field__clear {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+ width: 2.5rem;
+ height: 2.5rem;
+ padding: 0;
+ border: 0;
+ border-radius: 0.375rem;
+ background: transparent;
+ color: var(--text-muted);
+ font: 400 1.5rem var(--font-ui);
+ cursor: pointer;
+}
+
+.search-field__clear:hover {
+ background: var(--bg-tint);
+ color: var(--text-primary);
+}
+
+.search-field__clear:focus-visible {
+ outline: 2px solid var(--text-accent);
+ outline-offset: 2px;
+}
+
+/* ==========================================
+ MOBILTILPASNING – ISSUE #151
+ ========================================== */
+
+@media (max-width: 360px) {
+ .search-field {
+ min-width: 0;
+ }
+}
diff --git a/frontend/src/pages/SearchResults/SearchResultsPage.css b/frontend/src/pages/SearchResults/SearchResultsPage.css
index e86ebb1..a81aa35 100644
--- a/frontend/src/pages/SearchResults/SearchResultsPage.css
+++ b/frontend/src/pages/SearchResults/SearchResultsPage.css
@@ -1,6 +1,7 @@
/* ==========================================================================
HANDLELAPPEN – SØKERESULTATSIDE
- Issue #134 – Organisering av komponenter og CSS
+ Issue #134 – Organisering av komponenter og CSS
+ Issue #151 – Søkefelt under sideoverskriften
Felles layout og sidestiler for SearchResultsPage.
Farger og fonter hentes fra theme.css.
@@ -101,6 +102,33 @@
text-transform: uppercase;
}
+/* Søkefelt under sideoverskriften – issue #151. */
+
+.search-results-header__search {
+ width: 100%;
+ max-width: 43.75rem;
+ margin-top: 0.5rem;
+}
+
+.search-results-header__search-field {
+ width: 100%;
+ min-width: 0;
+ max-width: none;
+ height: 3.5rem;
+ padding: 0 0.5rem 0 1rem;
+ background: var(--bg-surface);
+ border: 1px solid var(--border-strong);
+ border-radius: 0.625rem;
+}
+
+.search-results-header__search-field:focus-within {
+ border-color: var(--text-accent);
+}
+
+.search-results-header__search-field .button {
+ flex-shrink: 0;
+}
+
/* ==========================================================================
3. HOVEDLAYOUT
========================================================================== */
@@ -251,6 +279,11 @@
margin-bottom: 24px;
}
+ /* Søket åpnes via søkeikonet i mobilheaderen. */
+ .search-results-header__search {
+ display: none;
+ }
+
/* Filtre og handleliste plasseres i samme kolonne. */
.search-results-filters,
.search-results-shopping-list {
diff --git a/frontend/src/pages/SearchResults/SearchResultsPage.tsx b/frontend/src/pages/SearchResults/SearchResultsPage.tsx
index c6ace98..1596240 100644
--- a/frontend/src/pages/SearchResults/SearchResultsPage.tsx
+++ b/frontend/src/pages/SearchResults/SearchResultsPage.tsx
@@ -1,31 +1,36 @@
import { useState } from "react";
-import { useSearchResults, PAGE_SIZE } from "./hooks/useSearchResults";
-
-import { useSearchState } from "./hooks/useSearchState";
-
-import { usePreserveScroll } from "./hooks/usePreserveScroll";
-
import FilterChip from "../../components/filterChip/FilterChip";
-
-import type { SearchSort } from "../../types/filters";
-
-import "./SearchResultsPage.css";
+import SearchField from "../../components/searchfield/SearchField";
+import Button from "../../components/button/Button";
import { useStoreNames } from "../../hooks/useStoreNames";
-// Underkomponenter for søkeresultatsiden
+import type { SearchSort } from "../../types/filters";
+
+import SearchEmptyState from "./components/SearchEmptyState";
import SearchFilters from "./components/SearchFilters";
import SearchPagination from "./components/SearchPagination";
import SearchProductList from "./components/SearchProductList";
import SearchSortSelect from "./components/SearchSortSelect";
-import SearchEmptyState from "./components/SearchEmptyState";
+
+import { usePreserveScroll } from "./hooks/usePreserveScroll";
+import { useSearchResults, PAGE_SIZE } from "./hooks/useSearchResults";
+import { useSearchState } from "./hooks/useSearchState";
+
+import "./SearchResultsPage.css";
const collator = new Intl.Collator("nb-NO", {
sensitivity: "base",
});
-export default function SearchResultsPage() {
+type SearchResultsPageProps = {
+ onSearch: (value: string) => void;
+};
+
+export default function SearchResultsPage({
+ onSearch,
+}: SearchResultsPageProps) {
// Søkeord, filtre, sortering og paginering håndteres i egen hook.
const {
searchTerm,
@@ -160,24 +165,40 @@ export default function SearchResultsPage() {
@@ -241,12 +262,11 @@ export default function SearchResultsPage() {
key={`category-${value}`}
label={`Kategori: ${getCategoryName(value)}`}
removeLabel={`Fjern kategorifilter ${getCategoryName(value)}`}
- onRemove={() => {
- preservePosition();
+ onRemove={() =>
handleCategoriesChange(
selectedCategories.filter((item) => item !== value),
- );
- }}
+ )
+ }
/>
))}
@@ -255,12 +275,11 @@ export default function SearchResultsPage() {
key={`store-${value}`}
label={`Kjede: ${getStoreName(value)}`}
removeLabel={`Fjern butikkfilter ${getStoreName(value)}`}
- onRemove={() => {
- preservePosition();
+ onRemove={() =>
handleStoresChange(
selectedStores.filter((item) => item !== value),
- );
- }}
+ )
+ }
/>
))}