Skip to content

fix: inspector Escape deletes bound text#50

Merged
avanelsas merged 1 commit into
mainfrom
fix/inspector-escape-clear
May 12, 2026
Merged

fix: inspector Escape deletes bound text#50
avanelsas merged 1 commit into
mainfrom
fix/inspector-escape-clear

Conversation

@avanelsas
Copy link
Copy Markdown
Owner

Summary

Pressing Escape inside any inspector text input silently erased the bound doc value. Affects every `x-search-field` widget in the inspector: attribute editors, layout fields (`:width` / `:height` / `:padding` / `:margin` / free-coord), name field, CSS-var editors, seed cells, field / action bind pickers, the add-action form, and the `:text` pseudo-property editor for x-typography / x-button. The CLAUDE.md smoke test for the inline-edit / inspector flow failed on this — clearest repro: select an x-typography in the SaaS template, type into the inspector text input, hit Esc → element becomes empty.

Root cause

BareDOM's `x-search-field` wraps an `` inside its shadow DOM (see baredom-2.9.0 `baredom/components/x_search_field/x_search_field.cljs`). Browsers handle Escape on `type="search"` as a clear gesture: they wipe the value and fire a native `input` event. BareDOM's input handler forwards that as `x-search-field-input` with `value=""`. The inspector's commit-on-input wiring then writes `""` back to the doc via `ops/set-text` (or `ops/set-attr` for attribute-mode text), erasing the user's text — every time, on any Esc press inside any of those inputs.

Fix

A single `search-field` helper at the top of `bareforge.ui.inspector` wraps `u/el :x-search-field` and attaches a `keydown` listener that `preventDefault`s Escape. Browser never clears, bogus commit never fires. All 12 inspector creation sites route through it; `render-field`'s generic widget dispatcher uses it when `widget-tag` is `:x-search-field`, so any future field spec that reuses the dispatcher inherits the fix automatically.

The palette filter input (`bareforge.ui.palette`) is intentionally untouched — it's a filter, not a binding, and clear-on-Escape is desired UX there.

Test plan

  • `clj-kondo --lint src test scripts` — 0 errors, 0 warnings
  • `cljfmt check` — clean
  • `npx shadow-cljs compile test` — 0 failures, 0 errors
  • `npx shadow-cljs release app` — 0 warnings
  • Manual smoke: select an x-typography in the SaaS template, type into the inspector text input, press Esc → text retained
  • Manual smoke: same flow on an x-alert (attribute-mode text) — text retained on Esc
  • Manual smoke: layout fields, name field, CSS-var fields — type → Esc → value retained
  • Manual smoke: palette filter — type → Esc → still clears (unchanged UX)

🤖 Generated with Claude Code

BareDOM's x-search-field wraps an `<input type="search">`. Browsers
treat Escape on type=search as a clear gesture — they wipe the value
AND fire an `input` event, which BareDOM forwards as
`x-search-field-input` with value="". Every inspector text widget
that commits on input then writes "" back to the doc, silently
erasing the user's text on every accidental Esc press inside an
attribute editor, layout field, name field, css-var, seed cell,
bind picker, or add-action form.

Wrap every inspector x-search-field through a single `search-field`
helper that attaches a keydown listener and preventDefaults Escape,
so the browser never clears the input and the bogus commit never
happens. render-field's generic widget creation routes through it
when widget-tag is :x-search-field, so any future field spec that
reuses the dispatcher inherits the fix.

The palette's filter input is left unchanged: there, clearing on
Escape is the desired UX (it's a filter, not a binding).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avanelsas avanelsas merged commit 68ca95d into main May 12, 2026
1 check passed
@avanelsas avanelsas deleted the fix/inspector-escape-clear branch May 12, 2026 13:52
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