diff --git a/CHANGELOG.md b/CHANGELOG.md index 537629f..23bc34f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v1.2.1 — 2026-07-22 + +- ⌨️ Weight and other numeric fields now accept a comma as decimal separator ("33,5") — iOS + decimal keyboards in many locales only offer a comma, which previously reset the field to 0. + Partial input like "33," no longer snaps to 0 while typing. (#13) + ## v1.2.0 — 2026-07-21 Localization — the whole app now speaks your language. (#7) diff --git a/frontend/package.json b/frontend/package.json index 9af1908..1be143d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "opengym-frontend", "private": true, - "version": "1.1.1", + "version": "1.2.1", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/src/components/NumField.jsx b/frontend/src/components/NumField.jsx new file mode 100644 index 0000000..6bdd63d --- /dev/null +++ b/frontend/src/components/NumField.jsx @@ -0,0 +1,31 @@ +import { useRef, useState } from 'react' + +// Numeric input that accepts "," as decimal separator — iOS decimal keypads in many +// locales only offer a comma, and type="number" reports "" for it (value snaps to 0). +// Keeps a local string draft while focused so partial input like "33," survives typing. +export default function NumField({ value, onChange, decimal = true, ...rest }) { + const [draft, setDraft] = useState(null) + const committed = useRef(null) + // external change (e.g. −/+ buttons) while a draft is showing → drop the draft + if (draft !== null && committed.current !== value) { setDraft(null); committed.current = null } + const commit = raw => { + let s = raw.replace(/,/g, '.').replace(/[^0-9.]/g, '') + const i = s.indexOf('.') + if (i !== -1) s = decimal ? s.slice(0, i + 1) + s.slice(i + 1).replace(/\./g, '') : s.slice(0, i) + const n = s === '' || s === '.' ? 0 : Math.max(0, parseFloat(s)) + committed.current = n + setDraft(s) + onChange(n) + } + return ( + e.target.select()} + onChange={e => commit(e.target.value)} + onBlur={() => { setDraft(null); committed.current = null }} + {...rest} + /> + ) +} diff --git a/frontend/src/components/Stepper.jsx b/frontend/src/components/Stepper.jsx index 9db809a..2801f82 100644 --- a/frontend/src/components/Stepper.jsx +++ b/frontend/src/components/Stepper.jsx @@ -1,16 +1,12 @@ +import NumField from './NumField.jsx' + // Number field with −/+ buttons; tapping the field selects its content so typing replaces. export default function Stepper({ value, step = 1, onChange, decimal = true, className = '', label }) { const set = v => onChange(Math.max(0, Math.round((v || 0) * 100) / 100)) const inner = (