Repository navigation
Write a playground's controls as a native form - #6231
Conversation
An author now writes a playground's controls as ordinary HTML: each `input`, `select` or `textarea` with a `name` in the playground is one field, radios that share a name are one field, and `<output for="NAME">` shows field NAME's value, in the instruction or beside a range. An `<aside>` directly inside the playground stands in the rail beside the preview; everything else it holds, except presets and `lf-playground-output`, is the preview. A `<button type="submit">` (with an optional `<button type="reset">`) written in the playground is its submission and Reset, replacing `actions="page"` and `registerActions`. The child tags `lf-playground-control`, `-choice`, `-value` and `-preview` are gone; presets keep `lf-playground-preset` and `lf-playground-setting`, whose `for` now names a field. The view no longer draws controls, labels, readings or choice cards, and no longer re-checks kinds, bounds, steps or colours: the browser's value sanitization decides what a field can hold, so a restored value a field can't hold shows its authored default, and a preset value it can't hold fails the playground. The fields stand in one `<form>` the view draws around the rail and the preview, which scopes a playground's radio groups and leaves a control in a form of its own (a candidate's demo, an inspection setting) out of the configuration. `tune` and `choose` record the same values as before; a field's value that differs from its authored one when the playground upgrades, the user's early edit or the browser's restoration of it, is an unsent edit, unless the tune in force holds it. `unit` is gone: a number reaches `--playground-NAME` bare, and the page writes `calc(var(--playground-radius) * 1px)`. `--playground-choice-columns` is gone: the page lays out and styles its candidates, and a press on the body of the box that holds one radio still selects it. Behavior that changed: - A label's words are a native `<label>`, so pressing them operates the control rather than selecting the words. - Go to (`g`) no longer reaches a playground's fields, as it reaches no page's own native controls. - A quoted playground shows its authored controls disabled at the quoted values rather than hiding them. - Duplicate field names, a preset or output naming no field, and a preset value its field can't hold fail the playground in the browser, which `page check` reports where the page runs code, rather than in the static check. `x-within` and keyed `x-refers` contracts, which only the playground's tags used, are removed from the registry vocabulary. Tests that protected the removed tags' static validation, plain-choice arrangement, the `actions="page"` hand-over failure, label selection and the switch's go-to hint are deleted or rewritten to the native behavior.
# Conflicts: # examples/code-comparison.html # examples/notification-playground.html
leaf-agent
left a comment
There was a problem hiding this comment.
tests/journeys/test_render_controls.py still expects the notification-playground #format radio's ring from > lf-playground-choice[data-lf-control-focus-visible] (in RING_CASES, just under the comment "a candidate card is the choice, so the card wears its radio's ring (playground/defaults.css)"). That rule left defaults.css with this PR, and no lf-playground-choice element is left in the tree, so this nightly journey case will fail. Now that the card is page CSS, the radio's label.lf-choice should wear the ring, the same as the #tone entry above it, so the expectation probably becomes .lf-choice[data-lf-control-focus-visible] (or the entry goes, since it would repeat #tone), and the comment needs rewriting. The line is outside the diff, so I couldn't leave a suggestion on it. I'm happy to push the edit if you want it.
| : nothing; | ||
| return html`<div class="lf-playground-split"> | ||
| ${!railed.length && presets.length ? controlsPane() : nothing} | ||
| return html`<form class="lf-playground-split"> |
There was a problem hiding this comment.
Wrapping the preview in this <form> puts every author-written <button> that has no type into the form as a submit button. Through implicit submission, pressing Enter in any text or number input in the playground, whether a field or a candidate's own unnamed input, now clicks the first such button. Before this PR the preview stood in no form, so Enter did nothing there. I checked this in Chromium: in <form><div><button>Replay</button></div><aside><input type=number></aside></form>, Enter in the input fires the button's click and then submit. The submit listener in lf-playground.js stops the navigation but not the click, so Enter in a field can replay a demo, open a candidate's menu, or, with no preview buttons, press whatever untyped button comes first. All the bundled examples type their buttons, but authored previews often leave type off.
Two fixes I can see, depending on which you want Enter to do:
- Make the form's first child a
<button type="submit" disabled hidden>. A disabled default button turns implicit submission off completely, which also stops Enter in a field from pressing a page's owntype="submit"button. - Keep the native behavior and tell authors in
author.mdthat a button in the preview needstype="button".
Merges main, whose #6224 reserves lf-choice, lf-field and lf-btn: the playground's examples, fixtures, tests, guide and eval inputs now write plain labels and fields, which a themed page draws with Leaf's faces, and the rail's and examples' rules name the label. Fixes from the review of #6231: - A radio group that reads none checked before the upgrade lost its check to a same-named group elsewhere on the page, since no press can clear a group; the drawing restores its value rather than reporting a selection it doesn't show. - A control its form attribute gives to a form is that form's, never a field, so two playgrounds no longer share radios a page's form claims. - Reset, and a preset for the fields it sets, rewrite those fields, so a number field the user cleared shows the value the playground sends. - A preset's colour may be written in capitals: the field holds it lowercase. - The focus-ring journey expects the plain label's ring on the notification playground's radios, rail and candidate alike.
Fixes the two tests [#6231](#6231) (the playground's native form) left failing on main: the `alert-thresholds` example read Leaf's private `--lf-choice-pad`, which `test_theme_tokens` refuses, and now uses `--lf-sp-1`, the value that pad resolves to; the prepared-install journey looked for `input[type=text]` on a field that writes no `type`, and now finds it by name. I merged #6231 with its `test` job red (my merge gate's exit status was swallowed by a pipe); both failures are its own. Both tests pass by node id. > _This was written by Claude Code on behalf of max-sixty_
…e it after this branch Main's native-form playground (#6231) added `:where(.lf-playground-controls-region > aside :is(input…, select, textarea))`, whose list left Chromium no key. The region and its aside now stand as an ancestor of their own, which Chromium's filter rejects on every row outside one (13 rules matched in full per plain row, selector stats). It matches the same elements at the same zero weight.
…he page wrote (#6309) The render gate's `apparatus among authored` check reported Leaf's own controls on every playground page because, since #6231, `lf-playground`'s content is the author's markup (the registry default), so `moduleOwnsBox` no longer treats its descendants as the module's. The bar of actions and instruction popover the playground builds inside it (a generated `<form>`, `.lf-playground-instruction-region`, `<footer>`, the popover head) are not the page's elements, yet the submit button, instruction title and `wa-copy-button` in them were read as standing among the author's markup. #6231 meant to make the fields native markup, not to change where Leaf's bar sits, so the gate was misreading a structure the change intended. The check now reports a Leaf element only where an element the page's source wrote (`servedElements()`) stands beside it, which is the situation the finding describes: only those siblings' `:first-child` or `h2 + p` rules change. If no source pairing is available, the check behaves as before. **Verification**, all `--run-nightly` by node id on Linux: - `test_page_fixture_renders[playground]`, `[alert-thresholds]` and `[data-explorer]` fail on main with only the apparatus findings and pass with this change. - `code-comparison`, `notification-playground` and `motion-playground` no longer report apparatus, but still fail on their other findings (below). - As a negative check, temporarily appending a `.lf-ui` div into the playground's `.lf-playground-stage` beside the author's preview content still produces the `apparatus among authored` finding, so the module's own box doesn't hide Leaf elements placed among the page's elements. - `pnpm run check:browser` passes. **What this leaves** of #6297, each with a separate cause: - `code-comparison`: the two `lf-code` candidates overlap at 720–760px, and the page scrolls sideways by 88px at 360–440px. These come from the example's rewritten candidate CSS. - `notification-playground`: at 760px the absolutely placed `.setting > output` covers its label's wrapped words. - `motion-playground`: writes at rest on `lf-playground#panel-motion` (`data-lf-user-override`, `childList`), plus a doubled `requestFrame`. - `test_render_controls.py::test_each_sampled_focus_ring_is_shown_whole_in_its_surface` on `motion-playground`. Part of #6297 — automated triage Co-authored-by: leaf-agent <[email protected]>
…ed (#6375) Since #6231, a playground reads every named `input`, `select` and `textarea` inside it as a field, inside the one `<form>` it draws around its rail and preview. A widget in the preview that draws named controls of its own then has them read as the page's fields. On motion-playground, `lf-motion`'s transport draws `<input name="time">` and `<select name="speed">`. The playground took both as fields and posted `tune {time: 0, speed: "1", timing: …}` while nobody touched the page. That event is the at-rest write the nightly render gate reports on `motion-playground`: `data-lf-user-override` and `childList` on `lf-playground#panel-motion`, and a `requestFrame` that ran twice. The `403` from `/api/event` in #6297's local teardown is the same post. The fix is one more condition in the playground's field membership ([`playground-view.js`](https://github.com/max-sixty/leaf/blob/c0015604d349bdb7b5f227e6e90e25bc62d279f4/packages/playground/widgets/playground-view.js#L186-L196)). A control inside an element marked `data-lf-gen` within the playground is no field. `offer`, `offerElement` and `generatedElement` write that mark on everything a widget generates, and `passages.js` reads it as "not authored". The view's header already said that an inspection setting in a form of its own is no field. A widget's generated controls now count the same way, without each widget having to drop `name` or wrap its controls in a form. The playground's own wrappers carry no such mark, so the page's fields are unaffected. A control a page script creates without the mark is still a field. **Verification** - `tests/runtime/playground-view.test.mjs` adds a generated range and select to its fixture. It fails before this change and passes after it. `pnpm run test:runtime` passes (1012). - `test_page_fixture_renders[motion-playground]` (`--run-nightly`, Linux) fails on main with the at-rest findings and passes with this change. A request listener on the served page records no `/api/event` post at rest after the change, where main posted the `tune` above. - `test_page_fixture_renders[playground|alert-thresholds|data-explorer]` and five field tests in `tests/browser/widgets/test_playgrounds.py` still pass. This leaves part of #6297. The focus-ring finding on motion-playground (`test_each_sampled_focus_ring_is_shown_whole_in_its_surface`) still fails with this change and has a separate cause, recorded on the issue. The code-comparison and notification-playground layout fixes are in #6373. Refs #6297 — automated triage Co-authored-by: leaf-agent <[email protected]>
…dings inside their boxes (#6373) #6231 rewrote the candidate and rail CSS of these two pages when playgrounds became native forms. The nightly render gate has failed on both since. This fixes each page's own CSS. The change's intent, cards drawn from the page's own CSS, is kept. - **code-comparison**: the page's module sets each candidate's `width` to the viewport slider's value (420px). `.treatment` was a grid with an implicit `auto` column, which grew to that width, so `max-width: 100%` never held the candidate to its card. At 720–760px candidate A's reader ran under candidate B's card, and at 360–440px the page scrolled sideways by 88px. The card's one column is now `minmax(0, 1fr)`, so the reader stays inside its card. - **notification-playground**: each setting's reading was absolutely placed at the top right, so at 760px it sat over "Concurrent release events" once those words wrapped. The setting is now a two-column grid with its label on a subgrid. The reading takes the second column of the words' first line, and the slider spans both columns as before. The reading aligns to the start of its row, so it stays above the slider and both sliders' maximum ends take a click. At the default 1440px window, `leaf-dev stills --authored` shows 0 changed pixels. `test_page_fixture_renders[code-comparison]` and `[notification-playground]` fail on main and pass with this change (`--run-nightly`, Linux). **States changed on screen** (`leaf-dev stills --authored`, base left, head right): code-comparison at 740×900, where the two cards stand side by side:   notification-playground's rail at 760×900:   At 400px wide, code-comparison's cards stack one per row, and each reader now fits its card with no sideways page scroll. This leaves the rest of #6297: `motion-playground`'s at-rest event, fixed in a separate PR, and the focus-ring finding on that page. Refs #6297 — automated triage --------- Co-authored-by: leaf-agent <[email protected]>
…ites the instruction (#7339) A playground's `<output for="NAME">` reading stopped following its field once the page's script registered an instruction provider: `render()` in `playground-view.js` filled readings only when no provider's instruction was drawn. The view now fills every reading on every draw, and a provider's instruction replaces only the `lf-playground-output`'s words. The playground's author instructions already promise this ("An `<output for="NAME">` anywhere in the playground shows field NAME's current value"), so no prose changes. The skip dates from when readings could stand only inside `lf-playground-output`, which a provider's instruction replaces whole; #6231 let a reading stand anywhere in the playground and kept the skip. The shipped `code-comparison` example shows it: with `leaf-dev probe --base`, two ArrowRight presses on its width range move the field to 460 while the reading stays at 420 on main and reads 460 on this branch. Max asked for the fix after a reading on one of his pages didn't move as he dragged its range. Tests: the new runtime test "a reading follows its field while a script's provider writes the instruction" fails on main (reading "3", expected "1.5") and passes here; `tests/runtime/playground-view.test.mjs` passes. > _This was written by Claude Code on behalf of max-sixty_
A playground's controls are now a native HTML form. The author writes ordinary fields inside
lf-playground, in an<aside>that is the rail: a range or number input, a checkbox withrole="switch", a<fieldset>of radios, a<select>, color and text inputs,<output for>for a reading, and the page's own<button type="submit">(andtype="reset"). Everything else in the playground is the preview. The child tagslf-playground-control,-choice,-valueand-previewgo, withx-withinand keyedx-refers, which only the playground used; presets and the agent's task text (lf-playground-output,-preset,-setting) keep their tags, since HTML has no element for either.Leaf reads fields by
nameinside one generated<form>around the rail and preview, which scopes each playground's radio groups.tuneandchooserecord exactly as before; the browser's own value checking replaces Leaf's range, step and colour checks, and numbers reach CSS bare (calc(var(--playground-radius) * 1px)). What changes for users: duplicate or unknown control names fail in the browser rather than inpage check, so a playground posted in a thread message is unchecked; pressing a label's words operates its control, reversing #6040/#6043;gno longer reaches playground fields; a quoted playground shows its fields disabled rather than hiding them. Candidate cards draw from the page's own CSS, 20 to 40 lines per example.Max picked this ("score it on the 15 cases, then land it as built") on a survey of places Leaf puts its own layer between authors and HTML. Scored on the 15 playground eval cases against main, Opus 5.5 author and judge: head passed 14 of 15, and
motion-design, its one failure (a claim about tap playback on the page's own script), passed 2 of 2 on a rerun; base passed 12 of 15, failing three cases whose rubrics are converted to the new markup. Tests:pnpm run check,test:runtime, the focused model tests, every playground browser test, and 16 other tests that use a playground. Source +501/−895, tests +441/−927.