2
2
3
3
import { CloseButton , Content , Heading , IllustratedMessage , SearchField , Tab , TabList , TabPanel , Tabs , Tag , TagGroup } from '@react-spectrum/s2' ;
4
4
import { ComponentCardItem , ComponentCardView } from './ComponentCardView' ;
5
- import { composeRenderProps , OverlayTriggerStateContext , Dialog as RACDialog , DialogProps as RACDialogProps } from 'react-aria-components' ;
6
5
import { getLibraryFromPage } from './library' ;
7
6
import { type Library , TAB_DEFS } from './constants' ;
8
7
// eslint-disable-next-line monorepo/no-internal-import
9
8
import NoSearchResults from '@react-spectrum/s2/illustrations/linear/NoSearchResults' ;
9
+ import { OverlayTriggerStateContext , Dialog as RACDialog , DialogProps as RACDialogProps } from 'react-aria-components' ;
10
10
import type { PageProps } from '@parcel/rsc' ;
11
- import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
11
+ import React , { useCallback , useContext , useEffect , useMemo , useRef , useState } from 'react' ;
12
12
import { style } from '@react-spectrum/s2/style' with { type : 'macro' } ;
13
13
14
14
@@ -55,13 +55,7 @@ const MobileCustomDialog = function MobileCustomDialog(props: MobileDialogProps)
55
55
return (
56
56
< RACDialog
57
57
{ ...props }
58
- className = { dialogStyle ( { padding} ) } >
59
- { composeRenderProps ( props . children , ( children ) => (
60
- < OverlayTriggerStateContext . Provider value = { null } >
61
- { children }
62
- </ OverlayTriggerStateContext . Provider >
63
- ) ) }
64
- </ RACDialog >
58
+ className = { dialogStyle ( { padding} ) } />
65
59
) ;
66
60
} ;
67
61
@@ -103,7 +97,7 @@ function MobileNav({pages, currentPage}: PageProps) {
103
97
} ) ;
104
98
return sectionArray ;
105
99
} , [ getSectionsForLibrary , selectedLibrary ] ) ;
106
-
100
+
107
101
108
102
useEffect ( ( ) => {
109
103
// Auto-select first section initially or when library changes
@@ -168,7 +162,7 @@ function MobileNav({pages, currentPage}: PageProps) {
168
162
if ( ! searchValue . trim ( ) ) {
169
163
return pages ;
170
164
}
171
-
165
+
172
166
let searchLower = searchValue . toLowerCase ( ) ;
173
167
return pages . filter ( page => {
174
168
let pageTitle = title ( page ) . toLowerCase ( ) ;
@@ -179,9 +173,9 @@ function MobileNav({pages, currentPage}: PageProps) {
179
173
let getSectionContent = ( sectionName : string , libraryId : string , searchValue : string = '' ) : ComponentCardItem [ ] => {
180
174
let librarySections = getSectionsForLibrary ( libraryId ) ;
181
175
let pages = librarySections . get ( sectionName ) ?? [ ] ;
182
-
176
+
183
177
let filteredPages = filterPages ( pages , searchValue ) ;
184
-
178
+
185
179
return filteredPages
186
180
. sort ( ( a , b ) => title ( a ) . localeCompare ( title ( b ) ) )
187
181
. map ( page => ( { id : page . url . replace ( / ^ \/ / , '' ) , name : title ( page ) , href : page . url } ) ) ;
@@ -209,7 +203,7 @@ function MobileNav({pages, currentPage}: PageProps) {
209
203
let getSectionNamesForLibrary = ( libraryId : string ) => {
210
204
let librarySections = getSectionsForLibrary ( libraryId ) ;
211
205
let sectionArray = [ ...librarySections . keys ( ) ] ;
212
-
206
+
213
207
// Show 'Components' first
214
208
sectionArray . sort ( ( a , b ) => {
215
209
if ( a === 'Components' ) {
@@ -220,7 +214,7 @@ function MobileNav({pages, currentPage}: PageProps) {
220
214
}
221
215
return a . localeCompare ( b ) ;
222
216
} ) ;
223
-
217
+
224
218
return sectionArray ;
225
219
} ;
226
220
@@ -263,10 +257,11 @@ function MobileNav({pages, currentPage}: PageProps) {
263
257
scrollContainerRef . current . scrollTo ( { top : 0 , behavior : 'auto' } ) ;
264
258
}
265
259
} , [ selectedSection , selectedLibrary ] ) ;
260
+ let state = useContext ( OverlayTriggerStateContext ) ;
266
261
267
262
return (
268
263
< div className = { style ( { minHeight : '100dvh' , paddingBottom : 24 , boxSizing : 'border-box' } ) } >
269
- < Tabs
264
+ < Tabs
270
265
aria-label = "Libraries"
271
266
density = "compact"
272
267
selectedKey = { selectedLibrary }
@@ -294,16 +289,16 @@ function MobileNav({pages, currentPage}: PageProps) {
294
289
ref = { headerRef }
295
290
className = { style ( { position : 'sticky' , zIndex : 1 , backgroundColor : 'layer-2' } ) }
296
291
style = { { top : tabListHeight } } >
297
- < SearchField
298
- aria-label = "Search"
292
+ < SearchField
293
+ aria-label = "Search"
299
294
value = { searchValue }
300
295
onChange = { handleSearchChange }
301
296
onFocus = { handleSearchFocus }
302
297
onBlur = { handleSearchBlur }
303
298
styles = { style ( { marginY : 12 } ) } />
304
299
< TagGroup
305
- aria-label = "Navigation sections"
306
- selectionMode = "single"
300
+ aria-label = "Navigation sections"
301
+ selectionMode = "single"
307
302
selectedKeys = { selectedSection ? [ selectedSection ] : [ ] }
308
303
onSelectionChange = { handleTagSelection }
309
304
styles = { style ( { margin : 12 } ) }
@@ -313,6 +308,7 @@ function MobileNav({pages, currentPage}: PageProps) {
313
308
</ div >
314
309
< div ref = { scrollContainerRef } >
315
310
< ComponentCardView
311
+ onAction = { ( ) => state ?. close ( ) }
316
312
items = { getItemsForSelection ( selectedSection , library . id , searchValue ) }
317
313
ariaLabel = "Pages"
318
314
size = "S"
0 commit comments