Skip to content

Commit bd07a36

Browse files
authored
fix(site): auto-scroll detail panel into view on mobile when a measure is selected (#69)
1 parent 9dfddda commit bd07a36

2 files changed

Lines changed: 19 additions & 32 deletions

File tree

package-lock.json

Lines changed: 0 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/MeasureDetailPanel.jsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect, useRef } from 'react';
12
import { t } from '../i18n/strings.js';
23
import {
34
localized,
@@ -7,10 +8,26 @@ import {
78
} from '../data/grip.js';
89
import LicenseBadge from './LicenseBadge.jsx';
910

11+
// Breakpoint at which the layout switches to a single column (matches CSS).
12+
const MOBILE_BREAKPOINT = 1080;
13+
1014
export default function MeasureDetailPanel({ measure, lang, onClose }) {
15+
const panelRef = useRef(null);
16+
17+
useEffect(() => {
18+
if (
19+
measure &&
20+
panelRef.current &&
21+
typeof panelRef.current.scrollIntoView === 'function' &&
22+
window.innerWidth <= MOBILE_BREAKPOINT
23+
) {
24+
panelRef.current.scrollIntoView({ behavior: 'smooth', block: 'start' });
25+
}
26+
}, [measure]);
27+
1128
if (!measure) {
1229
return (
13-
<aside className="detail detail--empty" aria-live="polite">
30+
<aside ref={panelRef} className="detail detail--empty" aria-live="polite">
1431
<h2 className="detail__empty-title">{t(lang, 'selectMeasure')}</h2>
1532
<p className="detail__empty-hint">{t(lang, 'selectMeasureHint')}</p>
1633
</aside>
@@ -26,7 +43,7 @@ export default function MeasureDetailPanel({ measure, lang, onClose }) {
2643
measure.type === 'T' ? t(lang, 'technical') : t(lang, 'organisational');
2744

2845
return (
29-
<aside className="detail" aria-live="polite">
46+
<aside ref={panelRef} className="detail" aria-live="polite">
3047
<header className="detail__head">
3148
<div className="detail__head-meta">
3249
<span className="detail__code">{measure.code}</span>

0 commit comments

Comments
 (0)