Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Rest bar: Skip and Dismiss become an icon when the label would be cut, named in full for screen readers

Duarte Santos2d922fc83e0d
diff --git a/frontend/src/components/Icon.jsx b/frontend/src/components/Icon.jsx
index 087181e46..33d17d86a 100644
--- a/frontend/src/components/Icon.jsx
+++ b/frontend/src/components/Icon.jsx
@@ -77,6 +77,7 @@ const P = {
link: <><path d="M10.2 13.8a3.6 3.6 0 0 0 5.4.4l2.6-2.6a3.6 3.6 0 0 0-5.1-5.1l-1.5 1.5" /><path d="M13.8 10.2a3.6 3.6 0 0 0-5.4-.4l-2.6 2.6a3.6 3.6 0 0 0 5.1 5.1l1.5-1.5" /></>,
play: <path d="M8.4 5.6 18 12l-9.6 6.4Z" />,
pause: <path d="M9.4 5.8v12.4M14.6 5.8v12.4" />,
+ skipForward: <><path d="M6.4 5.8 15.2 12l-8.8 6.2Z" /><path d="M18.2 5.8v12.4" /></>,
reset: <><path d="M4.4 12a7.6 7.6 0 1 0 2.3-5.4" /><path d="M4 4.4v4.4h4.4" /></>,
bell: <><path d="M6.6 10.4a5.4 5.4 0 0 1 10.8 0c0 4 1.4 5.6 1.4 5.6H5.2s1.4-1.6 1.4-5.6Z" /><path d="M10.1 19.2a2.1 2.1 0 0 0 3.8 0" /></>,
bellSlash: <><path d="M8.1 6.6a5.4 5.4 0 0 1 9.3 3.8c0 4 1.4 5.6 1.4 5.6H9.4M6.6 16H5.2s1.4-1.6 1.4-5.6v-.6" /><path d="M10.1 19.2a2.1 2.1 0 0 0 3.8 0M4 3.6l16 16.8" /></>,
diff --git a/frontend/src/components/RestTimer.dock.test.jsx b/frontend/src/components/RestTimer.dock.test.jsx
index 8888707cd..ce5e71ea6 100644
--- a/frontend/src/components/RestTimer.dock.test.jsx
+++ b/frontend/src/components/RestTimer.dock.test.jsx
@@ -64,7 +64,7 @@ describe('the docked rest bar', () => {
const slots = () => [...host.querySelectorAll('#timer .acts > button')].map(b => b.className.match(/adj|pause-slot|pause|skip/)[0])
expect(slots()).toEqual(['adj', 'adj', 'pause', 'skip'])
expect(host.querySelector('#timer .t').dataset.alt).toBe('Ready')
- const skipCell = () => [...host.querySelectorAll('#timer .skip > span > span')].map(s => s.textContent).sort()
+ const skipCell = () => [...host.querySelectorAll('#timer .skip > span:not(.skip-probe) > span')].map(s => s.textContent).sort()
expect(skipCell()).toEqual(['Dismiss', 'Skip'])
act(() => vi.advanceTimersByTime(1000))
expect(host.querySelector('#timer .t').textContent).toBe('Ready')
@@ -78,6 +78,27 @@ describe('the docked rest bar', () => {
expect(host.querySelector('#timer .skip .off').getAttribute('aria-hidden')).toBe('true')
})
+ it('shows Skip as an icon, named in full, when its label does not fit, and Dismiss as × once Ready', () => {
+ const rect = Element.prototype.getBoundingClientRect
+ Element.prototype.getBoundingClientRect = function () {
+ const r = rect.call(this)
+ return this.parentElement?.classList.contains('skip-probe') ? { ...r, width: 400 } : r
+ }
+ try {
+ act(() => useUI.getState().startRest(1, 0))
+ mount()
+ const skip = host.querySelector('#timer .skip')
+ expect(skip.classList.contains('icon-only')).toBe(true)
+ expect(skip.getAttribute('aria-label')).toBe('Skip')
+ expect(skip.querySelector('.on')).toBeNull()
+ expect(skip.querySelector('svg')).toBeTruthy()
+ act(() => vi.advanceTimersByTime(1000))
+ expect(host.querySelector('#timer .skip').getAttribute('aria-label')).toBe('Dismiss')
+ act(() => host.querySelector('#timer .skip').click())
+ expect(useUI.getState().timer).toBeNull()
+ } finally { Element.prototype.getBoundingClientRect = rect }
+ })
+
it('says Paused under the clock while the rest is held', () => {
act(() => useUI.getState().startRest(90, 0))
mount()
diff --git a/frontend/src/components/RestTimer.jsx b/frontend/src/components/RestTimer.jsx
index f6da3f486..ecc27e53a 100644
--- a/frontend/src/components/RestTimer.jsx
+++ b/frontend/src/components/RestTimer.jsx
@@ -1,4 +1,4 @@
-import { useEffect } from 'react'
+import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { useUI } from '../store/useUI.js'
import { t } from '../lib/i18n.js'
import { REST_MAX } from '../lib/duration.js'
@@ -45,11 +45,43 @@ export function applyRestLeft(v, opened) {
// bottom edge instead of floating as a card over the next set's row, and it is one row: the
// clock (tap to set it), then −15 s, +15 s, pause and Skip. The progress runs along its top edge,
// so it takes no width from the buttons. Elsewhere it sits on top of the tab bar.
+// Skip's label, when the longer of Skip and Dismiss would not fit beside the other buttons
+// (German or Russian on a 390 px phone): an icon then, named in full for a screen reader, rather
+// than "Überspr…". Measured from hidden copies of both labels, so the choice is the same for
+// counting and Ready and the row never reflows between them.
+function useSkipFits(actsRef, deps) {
+ const [fits, setFits] = useState(true)
+ useLayoutEffect(() => {
+ const acts = actsRef.current
+ if (!acts) return
+ const measure = () => {
+ const skip = acts.querySelector('.skip')
+ const probes = [...acts.querySelectorAll('.skip-probe > span')]
+ if (!skip || !probes.length) return
+ const need = Math.max(...probes.map(p => p.getBoundingClientRect().width))
+ const cs = getComputedStyle(skip)
+ const pad = parseFloat(cs.paddingLeft) + parseFloat(cs.paddingRight) + parseFloat(cs.borderLeftWidth) + parseFloat(cs.borderRightWidth)
+ const others = [...acts.children].filter(c => c !== skip).reduce((sum, c) => sum + c.getBoundingClientRect().width, 0)
+ const gap = parseFloat(getComputedStyle(acts).columnGap) || 0
+ const room = acts.clientWidth - others - gap * (acts.children.length - 1)
+ setFits(!(need > 0) || need + (pad || 0) <= room + 0.5)
+ }
+ measure()
+ if (typeof ResizeObserver === 'undefined') return
+ const ro = new ResizeObserver(measure)
+ ro.observe(acts)
+ return () => ro.disconnect()
+ }, deps)
+ return fits
+}
+
export default function RestTimer() {
const timer = useUI(s => s.timer)
const work = useUI(s => s.work)
const { addRest, stopRest, pauseRest, resumeRest, finishWorkEarly, stopWork } = useUI()
const on = work || timer
+ const actsRef = useRef(null)
+ const skipFits = useSkipFits(actsRef, [!!timer && !work, t('Skip'), t('Dismiss')])
// The page keeps room at its bottom for the bar (index.css body.resting), so the last set and
// the Finish button can scroll clear of it.
useEffect(() => {
@@ -88,7 +120,7 @@ export default function RestTimer() {
<span className="t" role={timer.ready ? 'status' : undefined} data-alt={timer.ready ? '0:00' : t('Ready')}>{timer.ready ? t('Ready') : clock(timer.left)}</span>
<span className="lbl">{label}<Icon name="chevronDown" /></span>
</button>
- <div className="acts">
+ <div className="acts" ref={actsRef}>
<Button size="sm" className="adj" icon="minus" onClick={() => addRest(-15)}>15s</Button>
<Button size="sm" className="adj" icon="plus" disabled={!timer.ready && timer.left >= REST_MAX} onClick={() => addRest(15)}>15s</Button>
{timer.ready
@@ -96,10 +128,14 @@ export default function RestTimer() {
: <Button size="sm" className="pause" icon={timer.paused ? 'play' : 'pause'}
aria-label={t(timer.paused ? 'Resume' : 'Pause')} aria-pressed={!!timer.paused}
onClick={timer.paused ? resumeRest : pauseRest} />}
- <Button size="sm" variant="primary" className="skip" onClick={stopRest}>
- <span className="on">{t(timer.ready ? 'Dismiss' : 'Skip')}</span>
- <span className="off" aria-hidden="true">{t(timer.ready ? 'Skip' : 'Dismiss')}</span>
- </Button>
+ <button type="button" className={'btn primary sm skip' + (skipFits ? '' : ' icon-only')} onClick={stopRest}
+ aria-label={skipFits ? undefined : t(timer.ready ? 'Dismiss' : 'Skip')}>
+ {skipFits
+ ? <span><span className="on">{t(timer.ready ? 'Dismiss' : 'Skip')}</span>
+ <span className="off" aria-hidden="true">{t(timer.ready ? 'Skip' : 'Dismiss')}</span></span>
+ : <Icon name={timer.ready ? 'xmark' : 'skipForward'} />}
+ <span className="skip-probe" aria-hidden="true"><span>{t('Skip')}</span><span>{t('Dismiss')}</span></span>
+ </button>
</div>
</div>
)
diff --git a/frontend/src/index.css b/frontend/src/index.css
index ddf018ef7..518849c7a 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -1304,8 +1304,8 @@ body.chips-dragging *{cursor:inherit}
@keyframes slideup{from{transform:translateY(16px);opacity:0}to{transform:none;opacity:1}}
#timer .bar{position:absolute;top:0;inset-inline-start:0;inset-inline-end:0;height:3px;background:var(--surface-3)}
#timer .bar i{display:block;height:100%;background:var(--acc);transition:width 1s linear}
-/* The clock is what the bar is for, so it never gives up width: the buttons do (Skip's label is
- the one that gives, ending in … in a long language on a narrow phone). The label under the
+/* The clock is what the bar is for, so it never gives up width: the buttons do (Skip is the one that
+ gives: in a long language on a narrow phone it becomes an icon, RestTimer.jsx useSkipFits). The label under the
clock fills the clock's width but does not widen it. */
#timer .tclock{flex:none;min-width:0;display:flex;flex-direction:column;align-items:flex-start;text-align:start;padding:2px 0}
#timer .t{font-size:28px;font-weight:600;line-height:1.1;letter-spacing:-.026em;font-variant-numeric:tabular-nums;white-space:nowrap}
@@ -1331,6 +1331,12 @@ body.chips-dragging *{cursor:inherit}
between counting and Ready; so does the pause slot, kept invisible once the rest is over. */
#timer .acts .skip > span > span{grid-area:1/1;min-width:0;overflow:hidden;text-overflow:ellipsis}
#timer .acts .skip .off,#timer .acts .pause-slot{visibility:hidden}
+/* Hidden copies of both labels, at their natural width, that RestTimer measures to decide
+ whether Skip shows its label or only its icon (skip-forward, or × once Ready). */
+#timer .acts .skip{position:relative}
+#timer .acts .skip > .skip-probe{position:absolute;inset-inline-start:0;top:0;visibility:hidden;pointer-events:none;display:block;overflow:visible;width:max-content}
+#timer .acts .skip > .skip-probe > span{display:block;width:max-content;white-space:nowrap}
+#timer .acts .skip.icon-only{min-width:0}
/* A paused rest reads as held: the clock and the bar step back until it runs again. */
#timer.rest.paused .t,#timer.rest.paused .bar{opacity:.5}
/* work timer (issue #16): the same bar doing the opposite job — outlined and tinted so a