Skip to content

Commit

Permalink
Facets filter button becomes fixed only after scrolling past chat res…
Browse files Browse the repository at this point in the history
…ponse UI elements
  • Loading branch information
adamjarling committed May 21, 2024
1 parent 64c6112 commit 6a9e1f8
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions components/Facets/Facets.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
import { FacetExtras, StyledFacets, Width, Wrapper } from "./Facets.styled";
import React, { useRef } from "react";
import React, { useEffect, useRef, useState } from "react";

import Container from "@/components/Shared/Container";
import FacetsFilter from "@/components/Facets/Filter/Filter";
import SearchPublicOnlyWorks from "@/components/Search/PublicOnlyWorks";
import WorkType from "@/components/Facets/WorkType/WorkType";
import { useSearchState } from "@/context/search-context";

const Facets: React.FC = () => {
const {
searchState: { searchFixed },
} = useSearchState();
const wrapperRef = useRef<HTMLDivElement>(null);
const [isFixed, setIsFixed] = useState<boolean>(false);

const facetsRef = useRef<HTMLDivElement>(null);

useEffect(() => {
const handleResize = () => {
if (wrapperRef.current) {
const rect = wrapperRef.current.getBoundingClientRect();
setIsFixed(rect.top < 70);
}
};

handleResize();

window.addEventListener("scroll", handleResize);

return () => {
window.removeEventListener("scroll", handleResize);
};
}, []);

return (
<Wrapper data-filter-fixed={searchFixed}>
<Wrapper ref={wrapperRef} data-filter-fixed={isFixed}>
<Container
className="facets-ui-container"
maxWidth={searchFixed ? facetsRef.current?.clientWidth : undefined}
maxWidth={isFixed ? facetsRef.current?.clientWidth : undefined}
>
<StyledFacets data-testid="facets-ui-wrapper" ref={facetsRef}>
<Width ref={facetsRef} />
Expand Down

0 comments on commit 6a9e1f8

Please sign in to comment.