22
33import { CloseButton , Content , Heading , IllustratedMessage , SearchField , Tab , TabList , TabPanel , Tabs , Tag , TagGroup } from '@react-spectrum/s2' ;
44import { ComponentCardItem , ComponentCardView } from './ComponentCardView' ;
5- import { composeRenderProps , OverlayTriggerStateContext , Dialog as RACDialog , DialogProps as RACDialogProps } from 'react-aria-components' ;
65import { getLibraryFromPage } from './library' ;
76import { type Library , TAB_DEFS } from './constants' ;
87// eslint-disable-next-line monorepo/no-internal-import
98import NoSearchResults from '@react-spectrum/s2/illustrations/linear/NoSearchResults' ;
9+ import { OverlayTriggerStateContext , Dialog as RACDialog , DialogProps as RACDialogProps } from 'react-aria-components' ;
1010import 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' ;
1212import { style } from '@react-spectrum/s2/style' with { type : 'macro' } ;
1313
1414
@@ -55,13 +55,7 @@ const MobileCustomDialog = function MobileCustomDialog(props: MobileDialogProps)
5555 return (
5656 < RACDialog
5757 { ...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} ) } />
6559 ) ;
6660} ;
6761
@@ -103,7 +97,7 @@ function MobileNav({pages, currentPage}: PageProps) {
10397 } ) ;
10498 return sectionArray ;
10599 } , [ getSectionsForLibrary , selectedLibrary ] ) ;
106-
100+
107101
108102 useEffect ( ( ) => {
109103 // Auto-select first section initially or when library changes
@@ -168,7 +162,7 @@ function MobileNav({pages, currentPage}: PageProps) {
168162 if ( ! searchValue . trim ( ) ) {
169163 return pages ;
170164 }
171-
165+
172166 let searchLower = searchValue . toLowerCase ( ) ;
173167 return pages . filter ( page => {
174168 let pageTitle = title ( page ) . toLowerCase ( ) ;
@@ -179,9 +173,9 @@ function MobileNav({pages, currentPage}: PageProps) {
179173 let getSectionContent = ( sectionName : string , libraryId : string , searchValue : string = '' ) : ComponentCardItem [ ] => {
180174 let librarySections = getSectionsForLibrary ( libraryId ) ;
181175 let pages = librarySections . get ( sectionName ) ?? [ ] ;
182-
176+
183177 let filteredPages = filterPages ( pages , searchValue ) ;
184-
178+
185179 return filteredPages
186180 . sort ( ( a , b ) => title ( a ) . localeCompare ( title ( b ) ) )
187181 . map ( page => ( { id : page . url . replace ( / ^ \/ / , '' ) , name : title ( page ) , href : page . url } ) ) ;
@@ -209,7 +203,7 @@ function MobileNav({pages, currentPage}: PageProps) {
209203 let getSectionNamesForLibrary = ( libraryId : string ) => {
210204 let librarySections = getSectionsForLibrary ( libraryId ) ;
211205 let sectionArray = [ ...librarySections . keys ( ) ] ;
212-
206+
213207 // Show 'Components' first
214208 sectionArray . sort ( ( a , b ) => {
215209 if ( a === 'Components' ) {
@@ -220,7 +214,7 @@ function MobileNav({pages, currentPage}: PageProps) {
220214 }
221215 return a . localeCompare ( b ) ;
222216 } ) ;
223-
217+
224218 return sectionArray ;
225219 } ;
226220
@@ -263,10 +257,11 @@ function MobileNav({pages, currentPage}: PageProps) {
263257 scrollContainerRef . current . scrollTo ( { top : 0 , behavior : 'auto' } ) ;
264258 }
265259 } , [ selectedSection , selectedLibrary ] ) ;
260+ let state = useContext ( OverlayTriggerStateContext ) ;
266261
267262 return (
268263 < div className = { style ( { minHeight : '100dvh' , paddingBottom : 24 , boxSizing : 'border-box' } ) } >
269- < Tabs
264+ < Tabs
270265 aria-label = "Libraries"
271266 density = "compact"
272267 selectedKey = { selectedLibrary }
@@ -294,16 +289,16 @@ function MobileNav({pages, currentPage}: PageProps) {
294289 ref = { headerRef }
295290 className = { style ( { position : 'sticky' , zIndex : 1 , backgroundColor : 'layer-2' } ) }
296291 style = { { top : tabListHeight } } >
297- < SearchField
298- aria-label = "Search"
292+ < SearchField
293+ aria-label = "Search"
299294 value = { searchValue }
300295 onChange = { handleSearchChange }
301296 onFocus = { handleSearchFocus }
302297 onBlur = { handleSearchBlur }
303298 styles = { style ( { marginY : 12 } ) } />
304299 < TagGroup
305- aria-label = "Navigation sections"
306- selectionMode = "single"
300+ aria-label = "Navigation sections"
301+ selectionMode = "single"
307302 selectedKeys = { selectedSection ? [ selectedSection ] : [ ] }
308303 onSelectionChange = { handleTagSelection }
309304 styles = { style ( { margin : 12 } ) }
@@ -313,6 +308,7 @@ function MobileNav({pages, currentPage}: PageProps) {
313308 </ div >
314309 < div ref = { scrollContainerRef } >
315310 < ComponentCardView
311+ onAction = { ( ) => state ?. close ( ) }
316312 items = { getItemsForSelection ( selectedSection , library . id , searchValue ) }
317313 ariaLabel = "Pages"
318314 size = "S"
0 commit comments