Skip to content

Commit 9cc22b5

Browse files
committed
properly close mobile header menu when clicking on component card
1 parent 7a4738d commit 9cc22b5

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

packages/dev/s2-docs/src/MobileHeader.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use client';
22

33
import {ActionButton, CloseButton, DialogTrigger} from '@react-spectrum/s2';
4-
import {composeRenderProps, OverlayTriggerStateContext, Dialog as RACDialog, DialogProps as RACDialogProps} from 'react-aria-components';
54
import {getCurrentLibrary, TAB_DEFS} from './SearchMenu';
65
import {keyframes} from '../../../@react-spectrum/s2/style/style-macro' with {type: 'macro'};
76
import MenuHamburger from '@react-spectrum/s2/icons/MenuHamburger';
87
import {Modal} from '../../../@react-spectrum/s2/src/Modal';
8+
import {Dialog as RACDialog, DialogProps as RACDialogProps} from 'react-aria-components';
99
import React, {CSSProperties, forwardRef, useEffect, useRef} from 'react';
1010
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
1111

@@ -96,13 +96,7 @@ const MobileCustomDialog = forwardRef<HTMLDivElement, MobileDialogProps>(functio
9696
<RACDialog
9797
{...props}
9898
ref={ref}
99-
className={dialogStyle({padding})}>
100-
{composeRenderProps(props.children, (children) => (
101-
<OverlayTriggerStateContext.Provider value={null}>
102-
{children}
103-
</OverlayTriggerStateContext.Provider>
104-
))}
105-
</RACDialog>
99+
className={dialogStyle({padding})} />
106100
</Modal>
107101
);
108102
});

packages/dev/s2-docs/src/Nav.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ComponentCardItem, ComponentCardView} from './ComponentCardView';
44
import {Content, Heading, IllustratedMessage, Picker, pressScale, SearchField, Tab, TabList, TabPanel, Tabs, Tag, TagGroup} from '@react-spectrum/s2';
55
import {focusRing, size, style} from '@react-spectrum/s2/style' with {type: 'macro'};
66
import {type Library, TAB_DEFS} from './SearchMenu';
7-
import {Link} from 'react-aria-components';
7+
import {Link, OverlayTriggerStateContext} from 'react-aria-components';
88
// eslint-disable-next-line monorepo/no-internal-import
99
import NoSearchResults from '@react-spectrum/s2/illustrations/linear/NoSearchResults';
1010
import type {PageProps} from '@parcel/rsc';
@@ -78,19 +78,20 @@ export function MobileNav({pages, currentPage}: PageProps) {
7878
return 'react-spectrum';
7979
};
8080

81+
let state = useContext(OverlayTriggerStateContext);
8182
let [selectedLibrary, setSelectedLibrary] = useState<Library>(getCurrentLibrary(currentPage));
8283

8384
let getSectionsForLibrary = useCallback((libraryId: string) => {
8485
let sectionsMap = new Map();
85-
86+
8687
let filteredPages = pages.filter(page => {
8788
let pageLibrary: 'react-spectrum' | 'react-aria' | 'internationalized' = 'react-spectrum';
8889
if (page.url.includes('react-aria')) {
8990
pageLibrary = 'react-aria';
9091
} else if (page.url.includes('react-internationalized')) {
9192
pageLibrary = 'internationalized';
9293
}
93-
94+
9495
return pageLibrary === libraryId;
9596
});
9697

@@ -118,7 +119,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
118119
});
119120
return sectionArray;
120121
}, [getSectionsForLibrary, selectedLibrary]);
121-
122+
122123

123124
useEffect(() => {
124125
// Auto-select first section initially or when library changes
@@ -184,7 +185,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
184185
if (!searchValue.trim()) {
185186
return pages;
186187
}
187-
188+
188189
let searchLower = searchValue.toLowerCase();
189190
return pages.filter(page => {
190191
let pageTitle = title(page).toLowerCase();
@@ -195,9 +196,9 @@ export function MobileNav({pages, currentPage}: PageProps) {
195196
let getSectionContent = (sectionName: string, libraryId: string, searchValue: string = ''): ComponentCardItem[] => {
196197
let librarySections = getSectionsForLibrary(libraryId);
197198
let pages = librarySections.get(sectionName) ?? [];
198-
199+
199200
let filteredPages = filterPages(pages, searchValue);
200-
201+
201202
return filteredPages
202203
.sort((a, b) => title(a).localeCompare(title(b)))
203204
.map(page => ({id: page.url.replace(/^\//, ''), name: title(page), href: page.url}));
@@ -225,7 +226,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
225226
let getSectionNamesForLibrary = (libraryId: string) => {
226227
let librarySections = getSectionsForLibrary(libraryId);
227228
let sectionArray = [...librarySections.keys()];
228-
229+
229230
// Show 'Components' first
230231
sectionArray.sort((a, b) => {
231232
if (a === 'Components') {
@@ -236,7 +237,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
236237
}
237238
return a.localeCompare(b);
238239
});
239-
240+
240241
return sectionArray;
241242
};
242243

@@ -282,7 +283,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
282283

283284
return (
284285
<div className={style({minHeight: '100dvh', paddingBottom: 24, boxSizing: 'border-box'})}>
285-
<Tabs
286+
<Tabs
286287
aria-label="Libraries"
287288
density="compact"
288289
selectedKey={selectedLibrary}
@@ -310,16 +311,16 @@ export function MobileNav({pages, currentPage}: PageProps) {
310311
ref={headerRef}
311312
className={style({position: 'sticky', zIndex: 1, backgroundColor: 'white'})}
312313
style={{top: tabListHeight}}>
313-
<SearchField
314-
aria-label="Search"
314+
<SearchField
315+
aria-label="Search"
315316
value={searchValue}
316317
onChange={handleSearchChange}
317318
onFocus={handleSearchFocus}
318319
onBlur={handleSearchBlur}
319320
styles={style({marginY: 12})} />
320321
<TagGroup
321-
aria-label="Navigation sections"
322-
selectionMode="single"
322+
aria-label="Navigation sections"
323+
selectionMode="single"
323324
selectedKeys={selectedSection ? [selectedSection] : []}
324325
onSelectionChange={handleTagSelection}
325326
styles={style({margin: 12})}
@@ -329,6 +330,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
329330
</div>
330331
<div ref={scrollContainerRef}>
331332
<ComponentCardView
333+
onAction={() => state?.close()}
332334
items={getItemsForSelection(selectedSection, library.id, searchValue)}
333335
ariaLabel="Pages"
334336
size="S"
@@ -503,7 +505,7 @@ export function MobileOnPageNav({children}) {
503505
visible.delete(entry.target);
504506
}
505507
}
506-
508+
507509
let lastVisible = elements.find(e => visible.has(e));
508510
if (lastVisible) {
509511
setSelected('#' + lastVisible.id!);

0 commit comments

Comments
 (0)