@@ -25,7 +25,7 @@ function Collaboration() {
2525 const [ selectedCategory , setSelectedCategory ] = useState ( '' ) ;
2626 const categoryRef = useRef ( null ) ;
2727 const positionRef = useRef ( null ) ;
28-
28+ const dropdownRef = useRef ( null ) ;
2929 // Modal
3030 const [ selectedJob , setSelectedJob ] = useState ( null ) ;
3131
@@ -127,21 +127,19 @@ function Collaboration() {
127127
128128 useEffect ( ( ) => {
129129 const handleClickOutside = event => {
130- if ( categoryRef . current && ! categoryRef . current . contains ( event . target ) ) {
130+ if ( dropdownRef . current && ! dropdownRef . current . contains ( event . target ) ) {
131131 setShowCategoryDropdown ( false ) ;
132132 }
133-
134- if ( positionRef . current && ! positionRef . current . contains ( event . target ) ) {
135- setShowPositionDropdown ( false ) ;
136- }
137133 } ;
138134
139- document . addEventListener ( 'mousedown' , handleClickOutside ) ;
135+ if ( showCategoryDropdown ) {
136+ document . addEventListener ( 'mousedown' , handleClickOutside ) ;
137+ }
140138
141139 return ( ) => {
142140 document . removeEventListener ( 'mousedown' , handleClickOutside ) ;
143141 } ;
144- } , [ ] ) ;
142+ } , [ showCategoryDropdown ] ) ;
145143
146144 /* ================= HANDLERS ================= */
147145 const handleSubmit = e => {
@@ -226,76 +224,34 @@ function Collaboration() {
226224 < button className = "btn btn-secondary" > Go</ button >
227225 </ form >
228226
229- < div className = { styles . dropdownWrapper } ref = { categoryRef } >
227+ < div ref = { dropdownRef } style = { { position : 'relative' } } >
230228 < button
231229 type = "button"
232- onClick = { ( ) => {
233- setShowCategoryDropdown ( prev => ! prev ) ;
234- setShowPositionDropdown ( false ) ;
235- } }
230+ onClick = { ( ) => setShowCategoryDropdown ( p => ! p ) }
236231 aria-expanded = { showCategoryDropdown }
237232 >
238- { selectedCategory || ' Select Categories' } ▼
233+ Select Categories ▼
239234 </ button >
240235
241236 { showCategoryDropdown && (
242237 < div className = { styles . jobSelect } >
243238 { categories . map ( cat => (
244- < button
245- key = { cat }
246- type = "button"
247- className = { styles . dropdownItem }
248- onClick = { ( ) => {
249- setSelectedCategory ( cat ) ;
250- setSelectedPosition ( '' ) ;
251- setShowCategoryDropdown ( false ) ;
252- setCurrentPage ( 1 ) ;
253- } }
254- >
239+ < label key = { cat } className = { styles . dropdownItem } >
240+ < input
241+ type = "checkbox"
242+ checked = { categoriesSelected . includes ( cat ) }
243+ onChange = { ( ) =>
244+ setCategoriesSelected ( prev =>
245+ prev . includes ( cat ) ? prev . filter ( c => c !== cat ) : [ ...prev , cat ] ,
246+ )
247+ }
248+ />
255249 { cat }
256- </ button >
250+ </ label >
257251 ) ) }
258252 </ div >
259253 ) }
260254 </ div >
261-
262- < div className = { styles . dropdownWrapper } ref = { positionRef } >
263- < button
264- type = "button"
265- disabled = { ! selectedCategory }
266- onClick = { ( ) => {
267- if ( ! selectedCategory ) return ;
268- setShowPositionDropdown ( prev => ! prev ) ;
269- setShowCategoryDropdown ( false ) ;
270- } }
271- aria-expanded = { showPositionDropdown }
272- >
273- { selectedPosition || 'Select Positions' } ▼
274- </ button >
275-
276- { showPositionDropdown && selectedCategory && (
277- < div className = { styles . jobSelect } >
278- { positions . length > 0 ? (
279- positions . map ( pos => (
280- < button
281- key = { pos }
282- type = "button"
283- className = { styles . dropdownItem }
284- onClick = { ( ) => {
285- setSelectedPosition ( pos ) ;
286- setShowPositionDropdown ( false ) ;
287- setCurrentPage ( 1 ) ;
288- } }
289- >
290- { pos }
291- </ button >
292- ) )
293- ) : (
294- < div className = { styles . dropdownItem } > No positions found</ div >
295- ) }
296- </ div >
297- ) }
298- </ div >
299255 </ nav >
300256
301257 { /* HEADINGS */ }
0 commit comments