diff --git a/app/routes/circulars._archive._index/DateSelectorMenu.tsx b/app/routes/circulars._archive._index/DateSelectorMenu.tsx index e455ef580..c18d76f5a 100644 --- a/app/routes/circulars._archive._index/DateSelectorMenu.tsx +++ b/app/routes/circulars._archive._index/DateSelectorMenu.tsx @@ -18,6 +18,7 @@ import { } from '@trussworks/react-uswds' import classNames from 'classnames' import { type ChangeEvent, useRef, useState } from 'react' +import { useOnClickOutside } from 'usehooks-ts' import DetailsDropdownContent from '~/components/DetailsDropdownContent' @@ -77,7 +78,11 @@ export function DateSelector({ defaultStartDate?: string defaultEndDate?: string }) { + const ref = useRef(null) const [showContent, setShowContent] = useState(false) + useOnClickOutside(ref, () => { + setShowContent(false) + }) const defaultShowDateRange = Boolean( (defaultStartDate && !dateSelectorLabels[defaultStartDate]) || defaultEndDate @@ -105,7 +110,7 @@ export function DateSelector({ } return ( - <> +
)} - +
) } diff --git a/app/routes/circulars._archive._index/SortSelectorButton.tsx b/app/routes/circulars._archive._index/SortSelectorButton.tsx index 58161de12..9f26823ad 100644 --- a/app/routes/circulars._archive._index/SortSelectorButton.tsx +++ b/app/routes/circulars._archive._index/SortSelectorButton.tsx @@ -16,7 +16,8 @@ import { } from '@trussworks/react-uswds' import classNames from 'classnames' import type { ChangeEvent } from 'react' -import { useState } from 'react' +import { useRef, useState } from 'react' +import { useOnClickOutside } from 'usehooks-ts' import DetailsDropdownContent from '~/components/DetailsDropdownContent' @@ -58,9 +59,12 @@ export function SortSelector({ form?: string defaultValue?: string }) { - const [showContent, setShowContent] = useState(false) - const submit = useSubmit() + const ref = useRef(null) + const [showContent, setShowContent] = useState(false) + useOnClickOutside(ref, () => { + setShowContent(false) + }) function radioOnChange({ target }: ChangeEvent) { setShowContent(false) @@ -88,7 +92,7 @@ export function SortSelector({ ) return ( - <> +
- +
) }