Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 12, 2025

Implements a lightweight inline text editor using contenteditable for labels and short text fields.

Changes

  • tsunami/frontend/src/element/editablediv.tsx - New component

    • Controlled component that syncs DOM text on prop changes
    • Fires onChange(newText) only on blur (no per-character callbacks)
    • Enter key submits the edit by triggering blur and firing onChange
    • Escape key reverts to original text and stops editing
    • Props: text, onChange, className, placeholder, plus passthrough for standard HTML attributes
  • tsunami/frontend/src/vdom.tsx - Register wave:editablediv in WaveTagMap

  • tsunami/frontend/src/tailwind.css - Placeholder styling via :empty:before pseudo-element

Usage

<wave:editablediv 
  text="Edit me" 
  onChange={(newText) => console.log(newText)}
  placeholder="Enter text..."
  className="text-sm px-2 py-1"
/>

Keyboard Behavior

  • Enter: Submits the edit and stops editing (triggers blur → onChange)
  • Escape: Reverts to original text and stops editing (no onChange fired)

The component uses Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> to avoid type conflicts between the custom onChange(string) signature and the standard HTML onChange(FormEvent).

Original prompt

I want to add a new element in tsunami/frontend/src/element/editablediv.tsx

(note do NOT modify the go.mod go.sum files in the tsunami demo dirs)

Component: wave:editablediv

Purpose:
Lightweight inline text editor using contenteditable.

Props:

  • className (string) — Tailwind classes for styling.
  • text (string) — current text value.
  • onChange (func(string)) — called once on blur with final text.
  • (optional) placeholder (string) — shown when empty.
  • also just pass through other props through to the underlying div e.g. style, aria, other event handlers etc.

Behavior:

  • Renders a <div contentEditable> showing text.
  • Syncs DOM text when text prop changes.
  • Fires onChange(newText) on blur.
  • Ignores intermediate keystrokes (no per-character updates).
  • Prevents default Enter key (single-line editing).
  • Adds a “placeholder” style when empty.

Goal:
Simple, controlled inline editor for labels or short text fields.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 12, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Add lightweight inline text editor component Add wave:editablediv component for inline text editing Nov 12, 2025
Copilot AI requested a review from sawka November 12, 2025 07:44
Copilot finished work on behalf of sawka November 12, 2025 07:44
@sawka
Copy link
Member

sawka commented Nov 12, 2025

@copilot for the keydown handler. Enter should "submit" it -- stop the content editing and fire the onChange event. And hitting "Escape" should revert it back to the original contents and stop editing.

Copy link
Contributor Author

Copilot AI commented Nov 12, 2025

@copilot for the keydown handler. Enter should "submit" it -- stop the content editing and fire the onChange event. And hitting "Escape" should revert it back to the original contents and stop editi...

Updated the keydown handler in commit d799b29:

  • Enter key now submits the edit by calling blur(), which triggers onChange with the new text
  • Escape key reverts the content to the original text stored in textRef.current and calls blur() to stop editing

Both keys prevent their default behavior and stop editing by blurring the contenteditable div.

Copilot finished work on behalf of sawka November 12, 2025 17:32
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.

3 participants