Skip to content

Commit 458bb9e

Browse files
committed
Make OnThisPage component renders collapsed on mobile
1 parent 4f36c77 commit 458bb9e

File tree

2 files changed

+10
-28
lines changed

2 files changed

+10
-28
lines changed

homedocs/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[x] Fix remaining Gallery themes
2424
[ ] Render presets to css
2525
[ ] Write Theme Migration Docs
26-
[ ] On this page should render closed on mobile
26+
[x] On this page should render closed on mobile
2727
[x] Move homedocs presets to cx-theme-variables
2828
[x] Make Stackblitz use cx-theme-variables
2929
[ ] Allow .md extension on each article

homedocs/src/components/OnThisPage.astro

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ interface Props {
88
const { collapsed = false } = Astro.props;
99
---
1010

11-
<aside class="on-this-page not-prose border border-border rounded-lg p-4 bg-card relative z-10 w-full mt-6 mb-6 xl:absolute xl:-right-58 xl:top-6 xl:mt-0 xl:mb-0 xl:ml-6 xl:w-64 xl:max-h-[calc(100vh-6rem)] xl:overflow-y-auto">
11+
<aside class="on-this-page not-prose border border-border rounded-lg p-4 bg-card relative z-10 w-full mt-6 mb-6 xl:absolute xl:-right-58 xl:top-6 xl:mt-0 xl:mb-0 xl:ml-6 xl:w-64 xl:max-h-[calc(100vh-6rem)] xl:overflow-y-auto" {...(collapsed ? { 'data-collapsed': '' } : {})}>
1212
<div>
1313
<button
1414
class="on-this-page-btn flex w-full items-center justify-between text-xs font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground transition-colors"
1515
type="button"
16-
aria-expanded={collapsed ? "false" : "true"}
16+
aria-expanded="false"
1717
>
1818
On This Page
1919
<svg
@@ -26,7 +26,7 @@ const { collapsed = false } = Astro.props;
2626
<path d="m6 9 6 6 6-6"/>
2727
</svg>
2828
</button>
29-
<nav class="on-this-page-content" data-open={collapsed ? "false" : "true"}>
29+
<nav class="on-this-page-content" data-open="false">
3030
<div class="text-sm on-this-page-links flex flex-col gap-2">
3131
<!-- Links will be populated by JavaScript -->
3232
</div>
@@ -80,29 +80,6 @@ const { collapsed = false } = Astro.props;
8080
font-size: small;
8181
}
8282

83-
/* Force collapsed on mobile */
84-
@media (max-width: 1279px) {
85-
.on-this-page-content {
86-
visibility: hidden;
87-
opacity: 0;
88-
height: 0;
89-
}
90-
91-
.on-this-page-content[data-open="true"] {
92-
visibility: visible;
93-
opacity: 1;
94-
height: auto;
95-
}
96-
97-
.on-this-page-btn .chevron {
98-
transform: rotate(-90deg);
99-
}
100-
101-
.on-this-page-btn[aria-expanded="true"] .chevron {
102-
transform: rotate(0deg);
103-
}
104-
}
105-
10683
.on-this-page:has(.on-this-page-content[data-open="true"]) {
10784
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
10885
}
@@ -164,10 +141,15 @@ const { collapsed = false } = Astro.props;
164141
linksList.appendChild(a);
165142
});
166143

167-
// Set up toggle button
168144
const btn = container.querySelector('.on-this-page-btn');
169145
const content = container.querySelector('.on-this-page-content');
170146

147+
// Expand on desktop if not explicitly collapsed
148+
if (btn && content && window.innerWidth >= 1280 && !container.hasAttribute('data-collapsed')) {
149+
btn.setAttribute('aria-expanded', 'true');
150+
content.setAttribute('data-open', 'true');
151+
}
152+
171153
if (btn && content) {
172154
// Remove existing listeners by cloning
173155
const newBtn = btn.cloneNode(true) as Element;

0 commit comments

Comments
 (0)