diff --git a/apps/storefront/src/components/header/mobile-search.tsx b/apps/storefront/src/components/header/mobile-search.tsx index 829c082..2e99907 100644 --- a/apps/storefront/src/components/header/mobile-search.tsx +++ b/apps/storefront/src/components/header/mobile-search.tsx @@ -1,7 +1,7 @@ "use client"; import { Search } from "lucide-react"; -import { useParams, usePathname } from "next/navigation"; +import { usePathname } from "next/navigation"; import { useTranslations } from "next-intl"; import { useEffect, useState } from "react"; @@ -14,12 +14,15 @@ export const MobileSearch = () => { const t = useTranslations("search"); const pathname = usePathname(); - const params = useParams(); const [isOpen, setIsOpen] = useState(false); + const handleCloseSheet = () => { + setIsOpen(false); + }; + useEffect(() => { setIsOpen(false); - }, [pathname, params]); + }, [pathname]); return ( <> @@ -38,8 +41,8 @@ export const MobileSearch = () => { aria-label={t("search-label")} modal={true} > - - + + diff --git a/apps/storefront/src/components/header/mobile-side-menu.tsx b/apps/storefront/src/components/header/mobile-side-menu.tsx index 816dcae..9201d64 100644 --- a/apps/storefront/src/components/header/mobile-side-menu.tsx +++ b/apps/storefront/src/components/header/mobile-side-menu.tsx @@ -13,6 +13,7 @@ import { Sheet, SheetContent } from "@nimara/ui/components/sheet"; import { MobileNavigation } from "@/components/mobile-navigation"; import { paths } from "@/lib/paths"; +import { cn } from "@/lib/utils"; import { useCurrentRegion } from "@/regions/client"; import { LocaleSwitch } from "../locale-switch"; @@ -57,7 +58,14 @@ export const MobileSideMenu = ({
-
+
diff --git a/apps/storefront/src/components/header/search-form.tsx b/apps/storefront/src/components/header/search-form.tsx index 4cc603d..ea7ef7f 100644 --- a/apps/storefront/src/components/header/search-form.tsx +++ b/apps/storefront/src/components/header/search-form.tsx @@ -54,7 +54,7 @@ const initialSearchState: SearchState = { showOptions: false, }; -export const SearchForm = () => { +export const SearchForm = ({ onSubmit }: { onSubmit?: () => void }) => { const ts = useTranslations("search"); const tc = useTranslations("common"); @@ -85,6 +85,9 @@ export const SearchForm = () => { if (event.code === keyboardCodes.Enter) { event.preventDefault(); resetSearchState(); + if (onSubmit) { + onSubmit(); + } // Handle query search if (isNoOptionHighlighted || isLastOptionHighlighted) { @@ -127,6 +130,15 @@ export const SearchForm = () => { } }; + const handleSearchIconClick = () => { + if (isNoOptionHighlighted || isLastOptionHighlighted) { + router.push(paths.search.asPath({ query: { q: inputValue } })); + resetSearchState(); + + return; + } + }; + useClickAnyWhere(() => setSearchState((prevState) => ({ ...prevState, showOptions: false })), ); @@ -173,7 +185,8 @@ export const SearchForm = () => { size="icon" type="submit" variant="outline" - onClick={() => resetSearchState()} + className="cursor-pointer" + onClick={handleSearchIconClick} > {isLoading ? ( diff --git a/packages/ui/src/components/sheet.tsx b/packages/ui/src/components/sheet.tsx index 7a31ab7..7166db9 100644 --- a/packages/ui/src/components/sheet.tsx +++ b/packages/ui/src/components/sheet.tsx @@ -54,12 +54,14 @@ const sheetVariants = cva( interface SheetContentProps extends React.ComponentPropsWithoutRef, - VariantProps {} + VariantProps { + closeClassName?: string; +} const SheetContent = React.forwardRef< React.ElementRef, SheetContentProps ->(({ side = "right", className, children, ...props }, ref) => ( +>(({ side = "right", className, closeClassName, children, ...props }, ref) => ( {children} - + Close