From a54e4b6e8a8ea6f2483498961850fabc8562a7af Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Sat, 19 Sep 2026 21:24:12 +0200 Subject: [PATCH] =?UTF-8?q?List=20view=20clears=20the=20sticky=20header=20?= =?UTF-8?q?at=20its=20real=20height=20=E2=80=94=20a=20wrapped=20workout=20?= =?UTF-8?q?name=20hid=20the=20current=20exercise's=20header=20row=20(QA=20?= =?UTF-8?q?C27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scroll margin that keeps the current unit out from under the pinned header was a fixed 96 px, the height of a one-line header. The header renders the session name without truncation, so a descriptive routine name or a two-routine "A + B" session makes it two to five lines tall and the unit's label, Current badge and menu ended up underneath it. Workout.jsx measures the header right before it scrolls and hands the height to the list as --whdr-h; .wl-unit's scroll-margin-top uses it (safe area included, since the header's padding carries it) and keeps the one-line height as the fallback. Measured on the QA rig (scripts/opengym-qa/run/fix-list-scroll/measure.mjs, gap from header bottom to the current unit's top, tab-bar return with "Set current" on the 4th exercise; before: negative = covered): 320 px 8ch 12 | 42ch (143 px header) 12, before −51 | 62ch (165) 12, before −73 368 px 8ch 11 | 42ch (121) 12, before −29 | 62ch (143) 12, before −51 412 px 8ch 11 | 42ch (99) 12, before −7 | 62ch (121) 12, before −29 backfilled session, 42ch name, via ⋯ → Layout → List at 368 px: 16 --- frontend/src/index.css | 6 ++++-- frontend/src/views/Workout.jsx | 7 ++++++- frontend/src/views/Workout.test.jsx | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/frontend/src/index.css b/frontend/src/index.css index 9fbcc37..10936fd 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -1165,8 +1165,10 @@ body.chips-dragging *{cursor:inherit} border-radius:var(--r-lg);padding:14px 14px 4px; background:var(--surface-2); } -/* scrolled to when the list opens (#224): clear the sticky header above it */ -.wl-unit{scroll-margin-top:calc(var(--sat) + 96px)} +/* scrolled to when the list opens (#224): clear the sticky header above it. Workout.jsx + measures the header (--whdr-h on .workout-list, safe area included) because it grows when + the session name wraps; the fallback is the height of a one-line header. */ +.wl-unit{scroll-margin-top:calc(var(--whdr-h, var(--sat) + 80px) + 16px)} .wl-unit.cur{box-shadow:inset 0 0 0 1.5px var(--acc-line)} .wl-hd{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:10px} @media (max-width:400px){ diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index 1eb5023..dee908e 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -590,6 +590,7 @@ function ActiveWorkout() { // where it was before the sheet opened, in an effect cleanup that runs before this one — // both would win over a scroll made right here. A frame asked for now runs after theirs. const listRef = useRef(null) + const hdrRef = useRef(null) useEffect(() => { if (!listMode) return const schedule = callback => window.requestAnimationFrame @@ -602,6 +603,10 @@ function ActiveWorkout() { const list = listRef.current const el = list?.querySelector('.wl-unit.cur') if (!el || typeof el.scrollIntoView !== 'function') return + // The sticky header grows when the workout name wraps; the unit's scroll margin (index.css) + // clears whatever height it has right now, with a one-line height as the fallback. + const hdrH = hdrRef.current?.offsetHeight + if (hdrH) list.style.setProperty('--whdr-h', hdrH + 'px') el.scrollIntoView({ block: 'start' }) }) return () => cancel(frame) @@ -960,7 +965,7 @@ function ActiveWorkout() { {/* In list mode the whole session scrolls under the header, so the header (name, clock, set counter, discard/finish, progress) stays pinned — the one thing you want in view while you are somewhere in the middle of a long stack. Cards mode never scrolls far. */} -
+
{A.name}
{A.backfill ? fmtDate(A.d, true) : } · {t('{0} sets', done + '/' + total)}
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx index a195acb..d7f06ab 100644 --- a/frontend/src/views/Workout.test.jsx +++ b/frontend/src/views/Workout.test.jsx @@ -20,6 +20,7 @@ const mocks = vi.hoisted(() => { exConfigSheet: vi.fn(), toast: vi.fn(), scrollCalls: [], + headerHeight: 0, swapActiveWorkoutExercise: vi.fn(), menuSheet: vi.fn(), effortPickerSheet: vi.fn(), @@ -121,6 +122,10 @@ function installDom() { dom.Element.prototype.scrollIntoView = vi.fn(function (options) { mocks.scrollCalls.push({ node: this, options }) }) + // linkedom has no layout; the sticky workout header reports the height a test gives it. + Object.defineProperty(dom.HTMLElement.prototype, 'offsetHeight', { + configurable: true, get() { return this.classList.contains('whdr') ? mocks.headerHeight : 0 }, + }) globalThis.IS_REACT_ACT_ENVIRONMENT = true container = document.getElementById('root') root = createRoot(container) @@ -200,6 +205,7 @@ beforeEach(() => { mocks.timer = null mocks.work = null mocks.scrollCalls.length = 0 + mocks.headerHeight = 0 }) afterEach(async () => { @@ -1028,6 +1034,14 @@ describe('workout list view', () => { expect(mocks.scrollCalls[0].node.classList.contains('cur')).toBe(true) }) + it('clears the sticky header at its measured height, not a one-line guess (QA C27)', async () => { + mocks.headerHeight = 143 // a routine name that wraps to three lines at 368 px + await mount([exercise('plain-bench', [true]), exercise('plain-row', [true]), exercise('plain-curl', [false])], 2, { workoutView: 'list' }) + await flushFrame() + expect(mocks.scrollCalls.length).toBe(1) + expect(container.querySelector('.workout-list').style.getPropertyValue('--whdr-h')).toBe('143px') + }) + it('re-anchors on the current exercise when the layout changes between list and compact (QA C1)', async () => { await mount([exercise('plain-bench', [true]), exercise('plain-row', [true]), exercise('plain-curl', [false])], 2, { workoutView: 'list' }) await flushFrame()