List view clears the sticky header at its real height — a wrapped workout name hid the current exercise's header row (QA C27)

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
This commit is contained in:
Duarte Santos committed 2026-09-19 21:24:12 +02:00
1 parent 6e39fbd4b4
commit a54e4b6e8a
3 files changed
+24 -3

No files matched your search

+4 -2
View File
@@ -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){
+6 -1
View File
@@ -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. */}
<div className={'whdr' + (listMode ? ' stick' : '')}>
<div className={'whdr' + (listMode ? ' stick' : '')} ref={hdrRef}>
<div className="hdr">
<button className="iconbtn" aria-label={t('Discard')} onClick={() => confirmSheet({ title: t('Discard workout?'), message: t('The sets you logged in this session will be lost.'), confirmText: t('Discard'), danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); stopWork(); nav('/home') } })}><Icon name="xmark" /></button>
<div style={{ textAlign: 'center' }}><div style={{ fontWeight: 600 }}>{A.name}</div><div className="sub">{A.backfill ? fmtDate(A.d, true) : <Elapsed start={A.start} />} · {t('{0} sets', done + '/' + total)}</div></div>
+14
View File
@@ -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()