Skip to content

textarea: Enter should insert a newline instead of submitting #46

Closed as not planned
liuyanghejerry/gpuiv
#53

Description

@chess10kp

Problem

The native multiline <textarea> binds plain Enter to Submit and Shift+Enter to Newline. A normal multiline editor therefore cannot insert a newline with Enter. If no onSubmit listener is registered, Enter visibly does nothing.

This is present in 0.6.0, 0.7.0, and current main:

KeyBinding::new("enter", Submit, context),
KeyBinding::new("shift-enter", Newline, context),

The same binding table is used for GpuixTextarea; newline already correctly replaces the current selection and emits change.

Source: https://github.com/remorses/gpuix/blob/main/packages/native/src/custom_elements/input.rs

Reproduction

Render a controlled multiline textarea without onSubmit:

<textarea value={value} onChange={(event) => setValue(event.value ?? '')} minRows={20} />

Focus it and press Enter in the middle of the buffer.

Expected: the current selection is replaced by \n, the caret moves after it, and onChange fires.

Actual: Submit runs; the value and caret do not change.

Suggested contract

  • <input>: Enter emits submit.
  • <textarea>: Enter invokes Newline.
  • Shift+Enter may also invoke Newline.
  • If chat/composer behavior is needed, expose it as an explicit textarea prop rather than making it the multiline default.

An application-side onSubmit workaround is not correct: the submit payload contains the full value but no caret/selection offsets, so JavaScript cannot insert at the native selection while preserving native undo, IME, and caret behavior.

Acceptance

  • Plain Enter in a textarea replaces the current selection with one newline.
  • The edit participates in native undo/redo and emits one change event.
  • Plain Enter in an input still emits submit.
  • Native tests cover insertion at the middle of a buffer and replacement of a selected range.

Activity

  1. added a commit that references this issue on Sep 6, 2026
    ff3c1a2
  2. added a commit that references this issue on Sep 14, 2026
    89b6799
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions