Skip to content

Pick dates from a calendar, and give colour fields a real picker - #63

Merged
AllTerrainDeveloper merged 2 commits into
mainfrom
feature/date-and-color-pickers
Oct 6, 2026
Merged

AllTerrainDeveloper merged 2 commits into
mainfrom
feature/date-and-color-pickers

Conversation

@AllTerrainDeveloper

Copy link
Copy Markdown
Owner

Why

Two pieces of feedback:

  1. Dates in the builder settings — people didn't know what to type into Earliest date / Latest date (or in what format). They asked for a date picker.
  2. Colour field on the front end — <input type="color" class="atf-input"> rendered as a full-width native swatch that read as a broken checkbox. It also couldn't be empty, so an optional colour nobody touched posted #000000.

What changed

Builder: dates are picked, not typed

  • New dateInput() in src/ui.ts, used for earliest/latest date, earliest/latest time, default answers on date/time/datetime fields, and the form's Open from / Closes schedule.
  • It's the browser's date/time control: it stores the ISO value the server compares (2026-10-31, 09:30, 2026-10-31T09:30) and shows it in the reader's own locale.
  • Clicking anywhere on the box opens the calendar (showPicker()).
  • The black native icon is swapped for a dashicon so it stays visible on a dark desktop, and the popup's color-scheme follows the box's actual background.
  • One-click clear button returns to "no limit".
  • A legacy hand-typed value the calendar can't show (e.g. 31/10/2026) is named under the box instead of being silently blanked.
  • Datetime fields bound with a date-and-time picker, since a bare date is not a valid min for datetime-local.
  • Colour fields get a colorInput() for their default: swatch, hex box, and it can be left empty.

Front end: a colour picker that fits every theme

  • The server renders a hex text box with a colour chip. It works with no JS, has a pattern, and is still the one named input.
  • src/color-picker.ts turns the chip into a button that opens a panel:
    • saturation/brightness area
    • hue track
    • optional suggested colours (new swatches setting on the Colour field)
    • EyeDropper where the browser supports it
    • No colour on optional fields
  • Styled only from the form theme tokens (--atf-surface, --atf-border, --atf-radius-*, focus ring, accent…), with radii capped so pill themes don't distort it. The theme-token contract tests still pass.
  • Accessible:
    • aria-expanded/aria-controls on the button and role="dialog" on the panel
    • both tracks are sliders with value text, fully keyboard-operable (arrows, Shift for big steps, Home/End, PageUp/PageDown)
    • Escape closes and returns focus; clicking outside or tabbing away also closes it
  • Writes go into the hex box with real input/change events, so logic, validation and submission see one value. It also works in repeater rows added later.
  • Values normalise to lower-case six-digit hex on both sides (alltfo_normalize_hex_color() ↔ normalizeHex(), with matching test tables). Inline validation reports a malformed code.

Tests

  • tests/phpunit/tests/colorField.php: markup, empty value, default, pattern, swatch cleaning (including an injection attempt), normaliser table, sanitisation. Full PHPUnit run: 793 OK.
  • tests/vitest/color-picker.test.ts: colour maths, enhancement, keyboard, swatches, clear, close behaviour, "only one input".
  • tests/vitest/date-settings.test.ts: date/time/datetime boxes, clear, legacy-value note, dark detection, colour default control.
  • Full vitest: 521 passed. tsc clean, PHPCS unchanged from baseline.

QA (localhost:8889)

  • Front end checked on the clean, brutal and neon (dark) themes: the panel picks up each theme's surface, border, radius and button shape.
  • Swatch pick, area click, Escape and value posting all verified.
  • Builder inspector checked in the dark OpenStation window. Found and fixed one issue: wp-admin's input[type=text] padding outranked the hex box's single-class rule, so the swatch covered the first digit.

🤖 Generated with Claude Code

AllTerrainDeveloper and others added 2 commits October 6, 2026 10:55
Feedback: people did not know what to type into the builder's date
settings, or in what format; and the front-end colour field rendered as a
full-width native swatch that read as a broken checkbox.

Builder: every date and time setting — earliest/latest date and time,
default answers on date/time/datetime fields, and the form's open/close
schedule — is now a native date/time picker that stores the ISO shape the
server compares against while showing the reader's own locale. A click
anywhere on the box opens the calendar, the native icon is replaced by a
dashicon that stays visible on a dark desktop, a clear button returns to
"no limit", and a hand-typed legacy value is named instead of blanked.
A datetime field's bounds use a date-and-time picker, since a bare date is
not a valid `min` for datetime-local.

Front end: the colour field is a hex text box (the one named input, which
works without JavaScript) with a chip that opens a picker — saturation/
brightness area, hue track, optional suggested swatches, the EyeDropper
where supported, and "No colour" on optional fields. It is drawn entirely
from the form theme's tokens so it fits every theme, is keyboard
operable, and an untouched optional colour now posts empty instead of
#000000. Values normalise to lower-case six-digit hex on both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The swatch was a native `<input type=color>` laid over the hex box. In
the builder window, wp-admin's `input[type=…]` rules outranked it: the
swatch picked up a grey frame and the code sat jammed against the colour.

It is now `<os-color-field>` when the kit is loaded (already in the
component list), drawn in shadow DOM from the shell's tokens like every
other swatch on the desktop. It sits beside the box in a flex row with
the shell's spacing, has a clear button for "no default", and shows a
struck tile, in the shell's well and muted ink, when empty. The raw
native input remains the fallback, held at two classes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AllTerrainDeveloper
AllTerrainDeveloper merged commit b678c7e into main Oct 6, 2026
3 checks passed
@AllTerrainDeveloper
AllTerrainDeveloper deleted the feature/date-and-color-pickers branch October 6, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant