Skip to content

Commit

Permalink
fix: Improve search experience
Browse files Browse the repository at this point in the history
  • Loading branch information
soniaklimas committed Sep 26, 2024
1 parent ca27f5b commit d9d9fd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 3 additions & 4 deletions apps/storefront/src/components/header/mobile-search.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -14,12 +14,11 @@ export const MobileSearch = () => {
const t = useTranslations("search");

const pathname = usePathname();
const params = useParams();
const [isOpen, setIsOpen] = useState(false);

useEffect(() => {
setIsOpen(false);
}, [pathname, params]);
}, [pathname]);

return (
<>
Expand All @@ -38,7 +37,7 @@ export const MobileSearch = () => {
aria-label={t("search-label")}
modal={true}
>
<SheetContent side="top">
<SheetContent side="top" closeClassName="right-2 top-2">
<SearchForm />
</SheetContent>
</Sheet>
Expand Down
13 changes: 10 additions & 3 deletions packages/ui/src/components/sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ const sheetVariants = cva(

interface SheetContentProps
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
VariantProps<typeof sheetVariants> {}
VariantProps<typeof sheetVariants> {
closeClassName?: string;
}

const SheetContent = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Content>,
SheetContentProps
>(({ side = "right", className, children, ...props }, ref) => (
>(({ side = "right", className, closeClassName, children, ...props }, ref) => (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
Expand All @@ -68,7 +70,12 @@ const SheetContent = React.forwardRef<
{...props}
>
{children}
<SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none">
<SheetPrimitive.Close
className={cn(
"ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none",
closeClassName,
)}
>
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
Expand Down

0 comments on commit d9d9fd5

Please sign in to comment.