Skip to content

Commit cbafcd3

Browse files
authored
docs: fix S2 docs mobile search bugs (#8964)
* fix mobile search modal position * only show mobile ToC if there are 1 or more subheadings
1 parent f2377a4 commit cbafcd3

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

packages/@react-spectrum/s2/src/Modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface ModalProps extends ModalOverlayProps {
2929

3030
const modalOverlayStyles = style({
3131
...colorScheme(),
32-
position: 'absolute',
32+
position: 'fixed',
3333
top: 0,
3434
left: 0,
3535
width: 'full',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function Layout(props: PageProps & {children: ReactElement<any>}) {
120120
})}>
121121
<Header pages={pages} currentPage={currentPage} />
122122
<MobileHeader
123-
toc={<MobileToc key="toc" toc={currentPage.tableOfContents ?? []} />}
123+
toc={(currentPage.tableOfContents?.[0]?.children?.length ?? 0) > 0 ? <MobileToc key="toc" toc={currentPage.tableOfContents ?? []} /> : null}
124124
pages={pages}
125125
currentPage={currentPage} />
126126
<div className={style({display: 'flex', width: 'full'})}>

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,30 @@ export function MobileHeader({toc, pages, currentPage}) {
130130
marginY: 0,
131131
...animation
132132
})}
133-
style={{
133+
style={toc ? {
134134
animationName: fadeOut,
135135
animationTimeline: 'scroll()',
136136
animationRange
137-
} as CSSProperties}>
137+
} as CSSProperties : undefined}>
138138
React Aria
139139
</h2>
140140
</div>
141-
<div
142-
className={style({
143-
...animation,
144-
position: 'absolute',
145-
left: '50%',
146-
translateX: '-50%'
147-
})}
148-
style={{
149-
animationName: fadeIn,
150-
animationTimeline: 'scroll()',
151-
animationRange
152-
} as CSSProperties}>
153-
{toc}
154-
</div>
141+
{toc && (
142+
<div
143+
className={style({
144+
...animation,
145+
position: 'absolute',
146+
left: '50%',
147+
translateX: '-50%'
148+
})}
149+
style={{
150+
animationName: fadeIn,
151+
animationTimeline: 'scroll()',
152+
animationRange
153+
} as CSSProperties}>
154+
{toc}
155+
</div>
156+
)}
155157
<DialogTrigger>
156158
<ActionButton aria-label="Navigation" isQuiet>
157159
<MenuHamburger />

0 commit comments

Comments
 (0)