@@ -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 { getLibraryFromPage , type Library } from './library' ;
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
// @ts -ignore
@@ -85,11 +85,12 @@ export function MobileNav({pages, currentPage}: PageProps) {
85
85
86
86
let getCurrentLibrary = ( page : any ) : Library => getLibraryFromPage ( page ) ;
87
87
88
+ let state = useContext ( OverlayTriggerStateContext ) ;
88
89
let [ selectedLibrary , setSelectedLibrary ] = useState < Library > ( getCurrentLibrary ( currentPage ) ) ;
89
90
90
91
let getSectionsForLibrary = useCallback ( ( libraryId : string ) => {
91
92
let sectionsMap = new Map ( ) ;
92
-
93
+
93
94
let filteredPages = pages . filter ( page => getLibraryFromPage ( page ) === libraryId ) ;
94
95
95
96
for ( let page of filteredPages ) {
@@ -116,7 +117,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
116
117
} ) ;
117
118
return sectionArray ;
118
119
} , [ getSectionsForLibrary , selectedLibrary ] ) ;
119
-
120
+
120
121
121
122
useEffect ( ( ) => {
122
123
// Auto-select first section initially or when library changes
@@ -182,7 +183,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
182
183
if ( ! searchValue . trim ( ) ) {
183
184
return pages ;
184
185
}
185
-
186
+
186
187
let searchLower = searchValue . toLowerCase ( ) ;
187
188
return pages . filter ( page => {
188
189
let pageTitle = title ( page ) . toLowerCase ( ) ;
@@ -193,9 +194,9 @@ export function MobileNav({pages, currentPage}: PageProps) {
193
194
let getSectionContent = ( sectionName : string , libraryId : string , searchValue : string = '' ) : ComponentCardItem [ ] => {
194
195
let librarySections = getSectionsForLibrary ( libraryId ) ;
195
196
let pages = librarySections . get ( sectionName ) ?? [ ] ;
196
-
197
+
197
198
let filteredPages = filterPages ( pages , searchValue ) ;
198
-
199
+
199
200
return filteredPages
200
201
. sort ( ( a , b ) => title ( a ) . localeCompare ( title ( b ) ) )
201
202
. map ( page => ( { id : page . url . replace ( / ^ \/ / , '' ) , name : title ( page ) , href : page . url } ) ) ;
@@ -223,7 +224,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
223
224
let getSectionNamesForLibrary = ( libraryId : string ) => {
224
225
let librarySections = getSectionsForLibrary ( libraryId ) ;
225
226
let sectionArray = [ ...librarySections . keys ( ) ] ;
226
-
227
+
227
228
// Show 'Components' first
228
229
sectionArray . sort ( ( a , b ) => {
229
230
if ( a === 'Components' ) {
@@ -234,7 +235,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
234
235
}
235
236
return a . localeCompare ( b ) ;
236
237
} ) ;
237
-
238
+
238
239
return sectionArray ;
239
240
} ;
240
241
@@ -280,7 +281,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
280
281
281
282
return (
282
283
< div className = { style ( { minHeight : '100dvh' , paddingBottom : 24 , boxSizing : 'border-box' } ) } >
283
- < Tabs
284
+ < Tabs
284
285
aria-label = "Libraries"
285
286
density = "compact"
286
287
selectedKey = { selectedLibrary }
@@ -308,16 +309,16 @@ export function MobileNav({pages, currentPage}: PageProps) {
308
309
ref = { headerRef }
309
310
className = { style ( { position : 'sticky' , zIndex : 1 , backgroundColor : 'layer-2' } ) }
310
311
style = { { top : tabListHeight } } >
311
- < SearchField
312
- aria-label = "Search"
312
+ < SearchField
313
+ aria-label = "Search"
313
314
value = { searchValue }
314
315
onChange = { handleSearchChange }
315
316
onFocus = { handleSearchFocus }
316
317
onBlur = { handleSearchBlur }
317
318
styles = { style ( { marginY : 12 } ) } />
318
319
< TagGroup
319
- aria-label = "Navigation sections"
320
- selectionMode = "single"
320
+ aria-label = "Navigation sections"
321
+ selectionMode = "single"
321
322
selectedKeys = { selectedSection ? [ selectedSection ] : [ ] }
322
323
onSelectionChange = { handleTagSelection }
323
324
styles = { style ( { margin : 12 } ) }
@@ -327,6 +328,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
327
328
</ div >
328
329
< div ref = { scrollContainerRef } >
329
330
< ComponentCardView
331
+ onAction = { ( ) => state ?. close ( ) }
330
332
items = { getItemsForSelection ( selectedSection , library . id , searchValue ) }
331
333
ariaLabel = "Pages"
332
334
size = "S"
@@ -510,7 +512,7 @@ export function MobileOnPageNav({children}) {
510
512
visible . delete ( entry . target ) ;
511
513
}
512
514
}
513
-
515
+
514
516
let lastVisible = elements . find ( e => visible . has ( e ) ) ;
515
517
if ( lastVisible ) {
516
518
setSelected ( '#' + lastVisible . id ! ) ;
0 commit comments