Skip to content

Show the new-key prompt as a placeholder, not a pre-filled value - #420

Merged
CarlosNZ merged 2 commits into
mainfrom
new-key-input-placeholder
Oct 2, 2026
Merged

CarlosNZ merged 2 commits into
mainfrom
new-key-input-placeholder

Conversation

@CarlosNZ

@CarlosNZ CarlosNZ commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

The new-key input (the text field that opens from + on an object) started with the KEY_NEW text as its value, selected on focus. Confirming without typing added a key literally called "Enter new key", or whatever a host's custom KEY_NEW text says (fig-tree-editor-react uses prompts such as "New variable name"). The prompt is now a placeholder: it shows the same text but can't be committed by accident.

Changes

  • EditButtons (src/ButtonPanels.tsx): the new-key state starts empty and resets to '' when the add session closes. The input takes placeholder={translate('KEY_NEW', nodeData)}, and the select-on-focus handler is removed because there's nothing to select.
  • commitAdd returns early on an empty key for both the free-text input and the newKeyOptions dropdown. Before, only the dropdown had this guard. Opening another node while an add is open still cancels the add session (EditingProvider.tsx), so the guard is only reached from ✓ and Enter.
  • "" is still a valid key, but the add input can't create one directly, because an empty field there means nothing was entered. To get one, add a key and rename it to ""; rename has no empty-key check.
  • The <Select> branch is unchanged.
  • CHANGELOG bullet under 2.0.3.

Tests

  • Updated test: "adding a property to an object: click Add, type a key, press Enter" now asserts that the input opens empty with "Enter new key" as its placeholder.
  • New test: "adding a property to an object: confirming with no key typed does nothing". Enter and ✓ on an empty input leave setData uncalled and the input open.
  • Checked against the old code: both tests fail against the previous ButtonPanels.tsx (the input started with a value, and setData was called) and pass with this change.
  • Other checks: pnpm test (772 passed), pnpm lint and npx tsc --noEmit are clean. pnpm format:check flags 5 files, but they fail on main too and none of them are touched here.

Browser checks (Chrome, via Playwright)

I drove these with real keyboard and mouse input in two places. The first was the demo, running in VITE_JRE_SOURCE=local mode. The second was a bare HTML page that loads the built bundle (build/index.esm.js) with no host CSS, which shows what a consumer without a CSS reset gets.

Where Check Result
Main demo, root object Click + Input focused, value '', placeholder "Enter new key", nothing selected
Main demo, root object Enter, then ✓, with nothing typed Session stays open, no key added
Main demo, root object Type fresh, Enter Key added, input closes
Main demo, root object Reopen after a commit; type abc, Esc, reopen Input empty each time
custom-text example + on library (level 0) and Rock (level 1) Value '', placeholders "Name a new genre…" and "New album title…" from the example's KEY_NEW function
new-key-restrictions example + on contact (newKeyOptions) Dropdown only, existing email excluded; Enter with nothing chosen is a no-op; choosing phone adds it
new-key-restrictions example + on tags (free-text fallback) Placeholder "Enter new key"; empty Enter is a no-op; urgent + Enter adds it
Main demo, Github Dark / Dracula / Black & White themes Placeholder legibility These themes keep the input white with dark text, and the grey placeholder is readable on it
Bare page, built bundle Open, empty Enter, then type fresh + Enter Same results; setData is only called after typing, with { string: 'Welcome', number: 99, fresh: null }

Placeholder colour: the stylesheet doesn't set one, so it comes from the host page or the browser. It's Chakra's rgb(113, 128, 150) in the demo and Chrome's default rgb(117, 117, 117) on the bare page. Themes don't change it, whereas the old pre-filled prompt rendered in the theme's input text colour.

Not checked: Firefox and Safari. Playwright's Firefox builds won't launch on this macOS version, so Firefox needs a manual look.

🤖 Generated with Claude Code

CarlosNZ and others added 2 commits October 2, 2026 20:53
The new-key input started with `translate('KEY_NEW')` as its value,
selected on focus, so confirming without typing added a key literally
called "Enter new key" (or whatever a host's custom `KEY_NEW` says). The
input now starts empty with the prompt as its placeholder, and
`commitAdd` treats an empty key as a silent no-op for both the
free-text input and the options dropdown.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Bundle size impact

json-edit-react

Format Base raw PR raw Δ raw Base gzip PR gzip Δ gzip
esm 59.01 KB 58.98 KB 🟢 -32 B (-0.05%) 20.92 KB 20.90 KB 🟢 -15 B (-0.07%)
cjs 60.45 KB 60.42 KB 🟢 -32 B (-0.05%) 20.94 KB 20.93 KB 🟢 -12 B (-0.06%)

Measured from build/index.{cjs,esm}.js. Gzip at level 9.

@CarlosNZ
CarlosNZ merged commit 6ca8c19 into main Oct 2, 2026
2 checks passed
@CarlosNZ
CarlosNZ deleted the new-key-input-placeholder branch October 2, 2026 10:29
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