diff --git a/components/Header/Header.styled.ts b/components/Header/Header.styled.ts index a3f5248f..70b75c26 100644 --- a/components/Header/Header.styled.ts +++ b/components/Header/Header.styled.ts @@ -92,6 +92,7 @@ const Primary = styled("div", { fontFamily: "$northwesternSansRegular", display: "flex", height: "$gr5", + marginLeft: "$gr4", a: { color: "$purple", @@ -152,10 +153,7 @@ const Primary = styled("div", { [`& ${NavStyled}`]: { width: "0", opacity: "0", - }, - - [`& ${SearchStyled}`]: { - marginRight: "0", + marginLeft: "0", }, }, }, diff --git a/components/Header/Primary.test.tsx b/components/Header/Primary.test.tsx index a2c276a7..1de82003 100644 --- a/components/Header/Primary.test.tsx +++ b/components/Header/Primary.test.tsx @@ -1,6 +1,7 @@ import { render, screen } from "@/test-utils"; import HeaderPrimary from "./Primary"; +import React from "react"; import { createDynamicRouteParser } from "next-router-mock/dynamic-routes"; import mockRouter from "next-router-mock"; @@ -38,16 +39,6 @@ describe("HeaderPrimary", () => { expect(search).toBeInTheDocument(); }); - it("renders the search jump to component", () => { - mockRouter.setCurrentUrl( - "https://devbox.library.northwestern.edu:3000/collections/1c2e2200-c12d-4c7f-8b87-a935c349898a", - ); - render(); - - expect(screen.queryByTestId("search-ui-component")).toBeNull(); - expect(screen.getByTestId("search-jump-to")).toBeInTheDocument(); - }); - it("renders browse collections link", () => { render(); const link = screen.getByText("Browse Collections"); diff --git a/components/Header/Primary.tsx b/components/Header/Primary.tsx index e15fd0d5..7a6a919c 100644 --- a/components/Header/Primary.tsx +++ b/components/Header/Primary.tsx @@ -5,16 +5,10 @@ import Container from "@/components/Shared/Container"; import Link from "next/link"; import Nav from "@/components/Nav/Nav"; import Search from "@/components/Search/Search"; -import SearchJumpTo from "@/components/Search/JumpTo"; import useElementPosition from "@/hooks/useElementPosition"; -import { useRouter } from "next/router"; import { useSearchState } from "@/context/search-context"; const HeaderPrimary: React.FC = () => { - const router = useRouter(); - const isCollectionPage = - router.pathname.includes("collection") && router.query.id; - const [searchActive, setSearchActive] = useState(false); const { @@ -48,12 +42,7 @@ const HeaderPrimary: React.FC = () => { > - {!isCollectionPage && ( - - )} - {isCollectionPage && ( - - )} + diff --git a/components/Search/JumpTo.styled.ts b/components/Search/JumpTo.styled.ts index ab691ef7..a6cdd800 100644 --- a/components/Search/JumpTo.styled.ts +++ b/components/Search/JumpTo.styled.ts @@ -28,9 +28,9 @@ const HelperStyled = styled("div", { }); const JumpToListStyled = styled("ul", { - position: "absolute", - left: "0px", - display: "block", + display: "flex", + flexDirection: "column", + alignSelf: "flex-end", margin: "0", padding: "0", background: "$white", @@ -38,20 +38,18 @@ const JumpToListStyled = styled("ul", { fontSize: "$gr2", listStyle: "none", top: "50px", - border: "1px solid $black10", - boxShadow: "3px 3px 8px #0003", + borderRadius: "3px", + boxShadow: "3px 3px 11px #0001", }); const JumpItem = styled("li", { position: "relative", - backgroundColor: "$gray6", transition: "$dcAll", "& a": { display: "block", padding: "$gr3", borderTopWidth: "1px", - borderTopColor: "$black20", borderTopStyle: "solid", cursor: "pointer", color: "$purple120", @@ -59,11 +57,12 @@ const JumpItem = styled("li", { "&[aria-selected='true']": { background: "$purple10", + fontFamily: "$northwesternSansBold", [`${HelperStyled}`]: { color: "$purple10", - background: "$purple", - boxShadow: "2px 2px 5px #0001", + background: "$purple120", + fontFamily: "$northwesternSansRegular", svg: { width: "$gr3", diff --git a/components/Search/JumpTo.test.tsx b/components/Search/JumpTo.test.tsx index 762578a1..bd466b33 100644 --- a/components/Search/JumpTo.test.tsx +++ b/components/Search/JumpTo.test.tsx @@ -1,43 +1,19 @@ import { render, screen } from "@/test-utils"; -import SearchJumpTo from "@/components/Search/JumpTo"; -import userEvent from "@testing-library/user-event"; -const mockIsSearchActive = jest.fn(); +import SearchJumpTo from "@/components/Search/JumpTo"; describe("SearchJumpTo component", () => { - it("renders the component", () => { - render( ({})} />); - const wrapper = screen.getByTestId("search-jump-to-form"); - expect(wrapper).toBeInTheDocument(); - }); - it("conditionally renders the SearchJumpTo component", async () => { - const user = userEvent.setup(); - render( -
- Outside search form - -
, - ); - const form = screen.getByTestId("search-jump-to-form"); - - await user.type(screen.getByRole("search"), "foo"); - - // JumpTo should be visible - expect(form).toHaveFormValues({ search: "foo" }); - expect(screen.getByRole("listbox")); - - // Click outside SearchJumpTo form, it should close JumpTo - await user.click(screen.getByText("Outside search form")); - - expect(screen.queryByRole("listbox")).not.toBeInTheDocument(); + render(); - // Type back in main search input, it should re-open JumpTo - await user.type(screen.getByRole("search"), "baz"); + const listbox = screen.getByRole("listbox"); + expect(listbox).toBeInTheDocument(); + expect(listbox).toHaveStyle({ top: "45px" }); - expect(form).toHaveFormValues({ - search: "foobaz", - }); - expect(screen.getByRole("listbox")); + for (let i = 0; i < listbox.children.length; i++) { + const item = listbox.children[i]; + expect(item).toBeInTheDocument(); + expect(item).toHaveTextContent("foo"); + } }); }); diff --git a/components/Search/JumpTo.tsx b/components/Search/JumpTo.tsx index 6455ad45..193b61d4 100644 --- a/components/Search/JumpTo.tsx +++ b/components/Search/JumpTo.tsx @@ -1,29 +1,27 @@ -import React, { - ChangeEvent, - FocusEvent, - useEffect, - useRef, - useState, -} from "react"; +import React, { useEffect, useRef, useState } from "react"; -import { IconSearch } from "@/components/Shared/SVG/Icons"; import SearchJumpToList from "@/components/Search/JumpToList"; -import { SearchStyled } from "./Search.styled"; import Swiper from "swiper"; interface SearchProps { - isSearchActive: (value: boolean) => void; + searchFocus: boolean; + searchValue: string; + top: number; } -const SearchJumpTo: React.FC = ({ isSearchActive }) => { - const search = useRef(null); +const SearchJumpTo: React.FC = ({ + searchFocus, + searchValue, + top, +}) => { const formRef = useRef(null); - const [searchValue, setSearchValue] = useState(""); - const [searchFocus, setSearchFocus] = useState(false); - const [isLoaded, setIsLoaded] = useState(false); const [showJumpTo, setShowJumpTo] = useState(false); - React.useEffect(() => { + useEffect(() => { + if (searchFocus) setShowJumpTo(Boolean(searchValue)); + }, [searchFocus, searchValue]); + + useEffect(() => { const handleMouseDown = (e: MouseEvent) => { if ( showJumpTo && @@ -66,49 +64,14 @@ const SearchJumpTo: React.FC = ({ isSearchActive }) => { }; }, [showJumpTo]); - const handleSearchFocus = (e: FocusEvent) => { - if (e.type === "focus") { - setSearchFocus(true); - setShowJumpTo(Boolean(searchValue)); - } else { - setSearchFocus(false); - } - }; - - const handleSearchChange = (e: ChangeEvent) => { - const value = e.target.value; - setSearchValue(value); - setShowJumpTo(Boolean(value)); - }; - - useEffect(() => { - setIsLoaded(true); - }, []); - - useEffect(() => { - !searchFocus && !searchValue ? isSearchActive(false) : isSearchActive(true); - }, [searchFocus, searchValue, isSearchActive]); + if (!showJumpTo) return null; return ( - - {/* temporarily setting to textarea for later refinement */} -