Skip to content

Commit d0873ea

Browse files
committed
feat(benchmark): improve tab navigation and styling for better mobile experience
1 parent 27fb18b commit d0873ea

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/components/tabbed-showcase/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,19 @@ export default function TabbedShowcase({
3737
role="tab"
3838
aria-selected={i === active}
3939
className={`${styles.tab} ${i === active ? styles.tabActive : ""}`}
40-
onClick={() => setActive(i)}
40+
onClick={(event) => {
41+
setActive(i);
42+
// On small screens the tab list scrolls
43+
// horizontally; keep the picked tab in view.
44+
const smooth = window.matchMedia(
45+
"(prefers-reduced-motion: no-preference)",
46+
).matches;
47+
event.currentTarget.scrollIntoView({
48+
behavior: smooth ? "smooth" : "auto",
49+
block: "nearest",
50+
inline: "nearest",
51+
});
52+
}}
4153
>
4254
<span className={styles.tabIcon} aria-hidden>
4355
{tab.icon}

src/components/tabbed-showcase/styles.module.css

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,47 @@
134134
@media (max-width: 996px) {
135135
.box {
136136
flex-direction: column;
137-
gap: 16px;
137+
gap: 12px;
138138
padding: 14px;
139139
}
140140

141+
/* Horizontal tab rail with a scroll affordance: the right edge fades out
142+
while more tabs are hiding there, and tabs snap into place. */
141143
.tabList {
142144
flex: none;
143145
flex-direction: row;
144146
overflow-x: auto;
145147
gap: 6px;
148+
scroll-snap-type: x proximity;
149+
scrollbar-width: thin;
150+
-webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent);
151+
mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent);
146152
}
147153

148154
.tab {
149155
flex: 0 0 auto;
150-
padding: 10px 14px;
156+
padding: 8px 12px;
157+
font-size: 14px;
151158
white-space: nowrap;
159+
scroll-snap-align: start;
160+
}
161+
162+
/* On small screens the box should hug the ACTIVE panel instead of the
163+
tallest one; the desktop no-jump trick wastes too much height here. */
164+
.panels {
165+
display: block;
166+
}
167+
168+
.panel {
169+
display: none;
170+
}
171+
172+
.panelActive {
173+
display: flex;
174+
visibility: visible;
175+
}
176+
177+
.desc {
178+
font-size: 15px;
152179
}
153180
}

0 commit comments

Comments
 (0)