Skip to content

Commit

Permalink
OPHJOD-1110: Close tool filters menu on outside click
Browse files Browse the repository at this point in the history
  • Loading branch information
juhaniko committed Dec 5, 2024
1 parent 0fa1810 commit c479d82
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/routes/Tool/Tool.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OpportunityCard, Title } from '@/components';
import { useEnvironment } from '@/hooks/useEnvironment';
import { useMenuClickHandler } from '@/hooks/useMenuClickHandler';
import { OpportunitiesFilter } from '@/routes/Tool';
import { MahdollisuusTyyppi } from '@/routes/types';
import { useToolStore } from '@/stores/useToolStore';
Expand Down Expand Up @@ -261,6 +262,9 @@ const YourOpportunities = () => {
const scrollRef = React.useRef<HTMLUListElement>(null);
const { isLoggedIn } = useLoaderData() as ToolLoaderData;
const [filtersOpen, setFiltersOpen] = React.useState(false);
const filterMenuButtonRef = React.useRef<HTMLButtonElement>(null);
const filterMenuRef = useMenuClickHandler(() => setFiltersOpen(false), filterMenuButtonRef);

const ehdotuksetCount = toolStore.ehdotuksetCount ?? {};
const filter = toolStore.filter;
const count =
Expand All @@ -282,12 +286,17 @@ const YourOpportunities = () => {
</span>
<button
className="text-form-label flex flex-row items-center gap-5"
ref={filterMenuButtonRef}
onClick={() => setFiltersOpen(!filtersOpen)}
>
<span className="font-arial">{t('do-filter')}</span>
<span className="flex bg-white rounded-full relative size-7 justify-center items-center">
<MdOutlineTune size={20} />
{filtersOpen && <OpportunitiesFilter />}
{filtersOpen && (
<div ref={filterMenuRef}>
<OpportunitiesFilter />
</div>
)}
</span>
</button>
</div>
Expand Down

0 comments on commit c479d82

Please sign in to comment.