Smoking habit tracker

refactor(settings): theme (light / dark) should be radio selectors #7

Open io-industries.dev
Open opened by io-industries.dev

refactor(settings): theme (light / dark) should be radio selectors #

Area: Settings · Display · Theme · pages/settings.vue Type: a11y / ui debt Priority: p2

Summary #

The Display → Theme control (light / dark) is currently a button group with aria-pressed and is missing the system option. It should be a native radio group with light / dark / system (or at minimum light / dark as radios — but system is in the schema and should be exposed).

Current behavior #

pages/settings.vue:162-176:

<span id="label-theme">{{ t('settings.theme') }}</span>
<div role="group" aria-labelledby="label-theme">
  <button :aria-pressed="settings.theme==='light'" @click="updateSettings('theme','light')">Light</button>
  <button :aria-pressed="settings.theme==='dark'" @click="updateSettings('theme','dark')">Dark</button>
</div>
  • Same button-group anti-pattern as Mode (see 05-*).
  • server/db/schema.ts:userSettings.theme is enum['light','dark','system'] with default system — UI hides system, so user can never return to system preference after picking light/dark.
  • applyTheme() in pages/settings.vue:24-33 already handles all three: light → marathon2026-light, dark → marathon2026, system → removeAttribute('data-theme').

Expected behavior #

<fieldset class="data-row">
  <legend id="label-theme" class="data-row-label">{{ t('settings.theme') }}</legend>
  <div class="flex gap-4">
    <label class="flex items-center gap-2 text-xs">
      <input type="radio" name="theme" value="light" :checked="settings.theme==='light'" @change="updateSettings('theme','light')">
      {{ t('settings.light') }}
    </label>
    <label class="flex items-center gap-2 text-xs">
      <input type="radio" name="theme" value="dark" :checked="settings.theme==='dark'" @change="updateSettings('theme','dark')">
      {{ t('settings.dark') }}
    </label>
    <label class="flex items-center gap-2 text-xs">
      <input type="radio" name="theme" value="system" :checked="settings.theme==='system'" @change="updateSettings('theme','system')">
      {{ t('settings.system') ?? 'System' }}
    </label>
  </div>
</fieldset>
  • If t('settings.system') key doesn't exist, add to i18n locales (en.json etc.).
  • Style consistent with 05 (mode radios) — flattened, no →, 44px hit area.
  • Changing radio calls updateSettings('theme', value) which already calls applyTheme(value) + persists to localStorage:smoker-theme.

Files to touch #

  • pages/settings.vue:162-176 — theme block, applyTheme (no logic change, just ensure system path tested)
  • i18n/locales/*.json — add settings.system if missing

Acceptance criteria #

How to test #

  1. Open Settings → Theme → should show 3 radios.
  2. Pick Light → page goes light; Dark → dark; System → follows OS (prefers-color-scheme).
  3. Reload → still on chosen value; check document.documentElement.getAttribute('data-theme').
Sign up or Sign in to add to the discussion.