Skip to content

Fix inconsistent Enter key behavior in Textbox for multiline inputs#13365

Open
Khushi-Roy-123 wants to merge 3 commits intogradio-app:mainfrom
Khushi-Roy-123:fix-textbox-submit
Open

Fix inconsistent Enter key behavior in Textbox for multiline inputs#13365
Khushi-Roy-123 wants to merge 3 commits intogradio-app:mainfrom
Khushi-Roy-123:fix-textbox-submit

Conversation

@Khushi-Roy-123
Copy link
Copy Markdown

@Khushi-Roy-123 Khushi-Roy-123 commented May 5, 2026

Problem

Enter key does not trigger submit for multiline Textbox (lines > 1), while Shift+Enter does.

Cause

Conditional logic in handle_keypress restricts Enter submission to single-line inputs.

Fix

  • Make Enter always trigger submit
  • Preserve Shift+Enter for newline behavior

Result

Consistent behavior across all Textbox configurations.

Fixes #13354


Note

Medium Risk
Changes core Textbox key handling so plain Enter always triggers onsubmit, which may alter UX for multiline textareas and affect flows that previously relied on Enter inserting a newline.

Overview
Unifies Textbox Enter key behavior by simplifying handle_keypress: plain Enter now always prevents default and calls onsubmit, regardless of lines/max_lines settings.

Shift+Enter is preserved for inserting a newline, and the component still calls oninput after key handling.

Reviewed by Cursor Bugbot for commit 6bbf895. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread js/textbox/shared/Textbox.svelte Outdated
Comment thread test_textbox.py Outdated
Comment thread gradio/package-lock.json Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8b32b04. Configure here.

Comment thread js/textbox/shared/Textbox.svelte Outdated
}
await tick();
oninput?.(value);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function body indentation is incorrect and inconsistent

Low Severity

The handle_keypress function body is indented at the same level as the function declaration (1 tab), and the closing brace is at 0 tabs. Every sibling function (handle_select, handle_scroll, etc.) has its body at 2 tabs and closing brace at 1 tab. This makes the code visually appear to close at the module level rather than the <script> block level.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8b32b04. Configure here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve updated the handler to ensure:

  • oninput is always triggered (even on Shift+Enter in multiline)
  • Enter behavior remains consistent across input types

Also aligned indentation with surrounding code style.

Pushing updates soon

@Khushi-Roy-123
Copy link
Copy Markdown
Author

Update pushed with clean implementation.

This change ensures:

  • Enter consistently triggers submit
  • Shift+Enter preserves newline behavior
  • oninput is always triggered

Happy to adjust if a different UX direction is preferred.

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.

Inconsistent behavior in gr.Textbox for submit event.

1 participant