Skip to content

Commit 348d56c

Browse files
committed
properly close mobile header menu when clicking on component card
1 parent 486475a commit 348d56c

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
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: 16 additions & 14 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 {getLibraryFromPage, type Library} from './library';
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
// @ts-ignore
@@ -85,11 +85,12 @@ export function MobileNav({pages, currentPage}: PageProps) {
8585

8686
let getCurrentLibrary = (page: any): Library => getLibraryFromPage(page);
8787

88+
let state = useContext(OverlayTriggerStateContext);
8889
let [selectedLibrary, setSelectedLibrary] = useState<Library>(getCurrentLibrary(currentPage));
8990

9091
let getSectionsForLibrary = useCallback((libraryId: string) => {
9192
let sectionsMap = new Map();
92-
93+
9394
let filteredPages = pages.filter(page => getLibraryFromPage(page) === libraryId);
9495

9596
for (let page of filteredPages) {
@@ -116,7 +117,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
116117
});
117118
return sectionArray;
118119
}, [getSectionsForLibrary, selectedLibrary]);
119-
120+
120121

121122
useEffect(() => {
122123
// Auto-select first section initially or when library changes
@@ -182,7 +183,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
182183
if (!searchValue.trim()) {
183184
return pages;
184185
}
185-
186+
186187
let searchLower = searchValue.toLowerCase();
187188
return pages.filter(page => {
188189
let pageTitle = title(page).toLowerCase();
@@ -193,9 +194,9 @@ export function MobileNav({pages, currentPage}: PageProps) {
193194
let getSectionContent = (sectionName: string, libraryId: string, searchValue: string = ''): ComponentCardItem[] => {
194195
let librarySections = getSectionsForLibrary(libraryId);
195196
let pages = librarySections.get(sectionName) ?? [];
196-
197+
197198
let filteredPages = filterPages(pages, searchValue);
198-
199+
199200
return filteredPages
200201
.sort((a, b) => title(a).localeCompare(title(b)))
201202
.map(page => ({id: page.url.replace(/^\//, ''), name: title(page), href: page.url}));
@@ -223,7 +224,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
223224
let getSectionNamesForLibrary = (libraryId: string) => {
224225
let librarySections = getSectionsForLibrary(libraryId);
225226
let sectionArray = [...librarySections.keys()];
226-
227+
227228
// Show 'Components' first
228229
sectionArray.sort((a, b) => {
229230
if (a === 'Components') {
@@ -234,7 +235,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
234235
}
235236
return a.localeCompare(b);
236237
});
237-
238+
238239
return sectionArray;
239240
};
240241

@@ -280,7 +281,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
280281

281282
return (
282283
<div className={style({minHeight: '100dvh', paddingBottom: 24, boxSizing: 'border-box'})}>
283-
<Tabs
284+
<Tabs
284285
aria-label="Libraries"
285286
density="compact"
286287
selectedKey={selectedLibrary}
@@ -308,16 +309,16 @@ export function MobileNav({pages, currentPage}: PageProps) {
308309
ref={headerRef}
309310
className={style({position: 'sticky', zIndex: 1, backgroundColor: 'layer-2'})}
310311
style={{top: tabListHeight}}>
311-
<SearchField
312-
aria-label="Search"
312+
<SearchField
313+
aria-label="Search"
313314
value={searchValue}
314315
onChange={handleSearchChange}
315316
onFocus={handleSearchFocus}
316317
onBlur={handleSearchBlur}
317318
styles={style({marginY: 12})} />
318319
<TagGroup
319-
aria-label="Navigation sections"
320-
selectionMode="single"
320+
aria-label="Navigation sections"
321+
selectionMode="single"
321322
selectedKeys={selectedSection ? [selectedSection] : []}
322323
onSelectionChange={handleTagSelection}
323324
styles={style({margin: 12})}
@@ -327,6 +328,7 @@ export function MobileNav({pages, currentPage}: PageProps) {
327328
</div>
328329
<div ref={scrollContainerRef}>
329330
<ComponentCardView
331+
onAction={() => state?.close()}
330332
items={getItemsForSelection(selectedSection, library.id, searchValue)}
331333
ariaLabel="Pages"
332334
size="S"
@@ -510,7 +512,7 @@ export function MobileOnPageNav({children}) {
510512
visible.delete(entry.target);
511513
}
512514
}
513-
515+
514516
let lastVisible = elements.find(e => visible.has(e));
515517
if (lastVisible) {
516518
setSelected('#' + lastVisible.id!);

0 commit comments

Comments
 (0)