@@ -4,7 +4,7 @@ import {ComponentCardItem, ComponentCardView} from './ComponentCardView';
4
4
import { Content , Heading , IllustratedMessage , Picker , pressScale , SearchField , Tab , TabList , TabPanel , Tabs , Tag , TagGroup } from '@react-spectrum/s2' ;
5
5
import { focusRing , size , style } from '@react-spectrum/s2/style' with { type : 'macro' } ;
6
6
import { type Library , TAB_DEFS } from './SearchMenu' ;
7
- import { Link } from 'react-aria-components' ;
7
+ import { Link , OverlayTriggerStateContext } from 'react-aria-components' ;
8
8
// eslint-disable-next-line monorepo/no-internal-import
9
9
import NoSearchResults from '@react-spectrum/s2/illustrations/linear/NoSearchResults' ;
10
10
import type { PageProps } from '@parcel/rsc' ;
@@ -78,19 +78,20 @@ export function MobileNav({pages, currentPage}: PageProps) {
78
78
return 'react-spectrum' ;
79
79
} ;
80
80
81
+ let state = useContext ( OverlayTriggerStateContext ) ;
81
82
let [ selectedLibrary , setSelectedLibrary ] = useState < Library > ( getCurrentLibrary ( currentPage ) ) ;
82
83
83
84
let getSectionsForLibrary = useCallback ( ( libraryId : string ) => {
84
85
let sectionsMap = new Map ( ) ;
85
-
86
+
86
87
let filteredPages = pages . filter ( page => {
87
88
let pageLibrary : 'react-spectrum' | 'react-aria' | 'internationalized' = 'react-spectrum' ;
88
89
if ( page . url . includes ( 'react-aria' ) ) {
89
90
pageLibrary = 'react-aria' ;
90
91
} else if ( page . url . includes ( 'react-internationalized' ) ) {
91
92
pageLibrary = 'internationalized' ;
92
93
}
93
-
94
+
94
95
return pageLibrary === libraryId ;
95
96
} ) ;
96
97
@@ -118,7 +119,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
118
119
} ) ;
119
120
return sectionArray ;
120
121
} , [ getSectionsForLibrary , selectedLibrary ] ) ;
121
-
122
+
122
123
123
124
useEffect ( ( ) => {
124
125
// Auto-select first section initially or when library changes
@@ -184,7 +185,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
184
185
if ( ! searchValue . trim ( ) ) {
185
186
return pages ;
186
187
}
187
-
188
+
188
189
let searchLower = searchValue . toLowerCase ( ) ;
189
190
return pages . filter ( page => {
190
191
let pageTitle = title ( page ) . toLowerCase ( ) ;
@@ -195,9 +196,9 @@ export function MobileNav({pages, currentPage}: PageProps) {
195
196
let getSectionContent = ( sectionName : string , libraryId : string , searchValue : string = '' ) : ComponentCardItem [ ] => {
196
197
let librarySections = getSectionsForLibrary ( libraryId ) ;
197
198
let pages = librarySections . get ( sectionName ) ?? [ ] ;
198
-
199
+
199
200
let filteredPages = filterPages ( pages , searchValue ) ;
200
-
201
+
201
202
return filteredPages
202
203
. sort ( ( a , b ) => title ( a ) . localeCompare ( title ( b ) ) )
203
204
. map ( page => ( { id : page . url . replace ( / ^ \/ / , '' ) , name : title ( page ) , href : page . url } ) ) ;
@@ -225,7 +226,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
225
226
let getSectionNamesForLibrary = ( libraryId : string ) => {
226
227
let librarySections = getSectionsForLibrary ( libraryId ) ;
227
228
let sectionArray = [ ...librarySections . keys ( ) ] ;
228
-
229
+
229
230
// Show 'Components' first
230
231
sectionArray . sort ( ( a , b ) => {
231
232
if ( a === 'Components' ) {
@@ -236,7 +237,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
236
237
}
237
238
return a . localeCompare ( b ) ;
238
239
} ) ;
239
-
240
+
240
241
return sectionArray ;
241
242
} ;
242
243
@@ -282,7 +283,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
282
283
283
284
return (
284
285
< div className = { style ( { minHeight : '100dvh' , paddingBottom : 24 , boxSizing : 'border-box' } ) } >
285
- < Tabs
286
+ < Tabs
286
287
aria-label = "Libraries"
287
288
density = "compact"
288
289
selectedKey = { selectedLibrary }
@@ -310,16 +311,16 @@ export function MobileNav({pages, currentPage}: PageProps) {
310
311
ref = { headerRef }
311
312
className = { style ( { position : 'sticky' , zIndex : 1 , backgroundColor : 'white' } ) }
312
313
style = { { top : tabListHeight } } >
313
- < SearchField
314
- aria-label = "Search"
314
+ < SearchField
315
+ aria-label = "Search"
315
316
value = { searchValue }
316
317
onChange = { handleSearchChange }
317
318
onFocus = { handleSearchFocus }
318
319
onBlur = { handleSearchBlur }
319
320
styles = { style ( { marginY : 12 } ) } />
320
321
< TagGroup
321
- aria-label = "Navigation sections"
322
- selectionMode = "single"
322
+ aria-label = "Navigation sections"
323
+ selectionMode = "single"
323
324
selectedKeys = { selectedSection ? [ selectedSection ] : [ ] }
324
325
onSelectionChange = { handleTagSelection }
325
326
styles = { style ( { margin : 12 } ) }
@@ -329,6 +330,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
329
330
</ div >
330
331
< div ref = { scrollContainerRef } >
331
332
< ComponentCardView
333
+ onAction = { ( ) => state ?. close ( ) }
332
334
items = { getItemsForSelection ( selectedSection , library . id , searchValue ) }
333
335
ariaLabel = "Pages"
334
336
size = "S"
@@ -503,7 +505,7 @@ export function MobileOnPageNav({children}) {
503
505
visible . delete ( entry . target ) ;
504
506
}
505
507
}
506
-
508
+
507
509
let lastVisible = elements . find ( e => visible . has ( e ) ) ;
508
510
if ( lastVisible ) {
509
511
setSelected ( '#' + lastVisible . id ! ) ;
0 commit comments