File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed
app/routes/circulars._archive._index Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
18
18
} from '@trussworks/react-uswds'
19
19
import classNames from 'classnames'
20
20
import { type ChangeEvent , useRef , useState } from 'react'
21
+ import { useOnClickOutside } from 'usehooks-ts'
21
22
22
23
import DetailsDropdownContent from '~/components/DetailsDropdownContent'
23
24
@@ -77,7 +78,11 @@ export function DateSelector({
77
78
defaultStartDate ?: string
78
79
defaultEndDate ?: string
79
80
} ) {
81
+ const ref = useRef < HTMLDivElement > ( null )
80
82
const [ showContent , setShowContent ] = useState ( false )
83
+ useOnClickOutside ( ref , ( ) => {
84
+ setShowContent ( false )
85
+ } )
81
86
const defaultShowDateRange = Boolean (
82
87
( defaultStartDate && ! dateSelectorLabels [ defaultStartDate ] ) ||
83
88
defaultEndDate
@@ -105,7 +110,7 @@ export function DateSelector({
105
110
}
106
111
107
112
return (
108
- < >
113
+ < div ref = { ref } >
109
114
< input
110
115
type = "hidden"
111
116
name = "startDate"
@@ -218,6 +223,6 @@ export function DateSelector({
218
223
</ CardFooter >
219
224
) }
220
225
</ DetailsDropdownContent >
221
- </ >
226
+ </ div >
222
227
)
223
228
}
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ import {
16
16
} from '@trussworks/react-uswds'
17
17
import classNames from 'classnames'
18
18
import type { ChangeEvent } from 'react'
19
- import { useState } from 'react'
19
+ import { useRef , useState } from 'react'
20
+ import { useOnClickOutside } from 'usehooks-ts'
20
21
21
22
import DetailsDropdownContent from '~/components/DetailsDropdownContent'
22
23
@@ -58,9 +59,12 @@ export function SortSelector({
58
59
form ?: string
59
60
defaultValue ?: string
60
61
} ) {
61
- const [ showContent , setShowContent ] = useState ( false )
62
-
63
62
const submit = useSubmit ( )
63
+ const ref = useRef < HTMLDivElement > ( null )
64
+ const [ showContent , setShowContent ] = useState ( false )
65
+ useOnClickOutside ( ref , ( ) => {
66
+ setShowContent ( false )
67
+ } )
64
68
65
69
function radioOnChange ( { target } : ChangeEvent < HTMLInputElement > ) {
66
70
setShowContent ( false )
@@ -88,7 +92,7 @@ export function SortSelector({
88
92
)
89
93
90
94
return (
91
- < >
95
+ < div ref = { ref } >
92
96
< SortButton
93
97
sort = { sanitizedValue }
94
98
expanded = { showContent }
@@ -108,6 +112,6 @@ export function SortSelector({
108
112
</ Grid >
109
113
</ CardBody >
110
114
</ DetailsDropdownContent >
111
- </ >
115
+ </ div >
112
116
)
113
117
}
You can’t perform that action at this time.
0 commit comments