Skip to content

fix: prevent Enter key from submitting form during autocomplete selection - #7221

Merged
bijin-bruno merged 1 commit into
usebruno:mainfrom
iyush05:bugfix/7215-enter-key-submits-on-autocomplete
Mar 27, 2026
Merged

fix: prevent Enter key from submitting form during autocomplete selection#7221
bijin-bruno merged 1 commit into
usebruno:mainfrom
iyush05:bugfix/7215-enter-key-submits-on-autocomplete

Conversation

@iyush05

@iyush05 iyush05 commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes unintended form submission when pressing Enter during variable autocomplete in the New Request model.

Previously, pressing Enter would both:

  • select the autocomplete option
  • and trigger form submission

This change ensures Enter only selects the autocomplete suggestion by respecting event handling and avoiding global submission.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Fixes #7215

Summary by CodeRabbit

  • Bug Fixes
    • Fixed unintended form submission when creating new requests. Pressing Enter while typing in input fields no longer triggers form submission. You can now type freely in text inputs, textareas, and other editable areas without accidentally submitting. The form will continue to submit on Enter when appropriate.

@coderabbitai

coderabbitai Bot commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Modified form submission logic in the NewRequest component to prevent unintended form submission when the Enter key is pressed in text inputs, textareas, or contenteditable elements. The change conditionally triggers submission only when the event hasn't been default-prevented and the target is not a text-like field.

Changes

Cohort / File(s) Summary
NewRequest Form Enter Handling
packages/bruno-app/src/components/Sidebar/NewRequest/index.js
Added guard conditions to prevent form submission on Enter when event is within text inputs, textareas, or contenteditable elements, allowing autocomplete dropdowns to function without triggering unwanted form submission.

Estimated code review effort

ðŸŽŊ 2 (Simple) | ⏱ïļ ~8 minutes

Suggested labels

size/XS

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno

Poem

ðŸŽđ Enter key behaves with grace,
No more forms in the wrong place,
Dropdowns autocomplete with care,
While submission waits its time there! âœĻ

ðŸšĨ Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: preventing Enter key from submitting the form during autocomplete selection, which directly addresses the changeset.
Linked Issues check ✅ Passed The code changes directly address issue #7215 by preventing form submission when Enter is pressed during autocomplete selection in the NewRequest modal.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to the NewRequest form's Enter key handling and directly relate to the linked issue objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏ïļ Tip: You can configure your own custom pre-merge checks in the settings.

âœĻ Finishing Touches
  • 📝 Generate docstrings
🧊 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

âĪïļ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

ðŸĪ– Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-app/src/components/Sidebar/NewRequest/index.js`:
- Around line 319-330: Rename the local variable isTextInput to isEditableTarget
inside the onKeyDown handler in the NewRequest component, and add a concise
inline comment above the logic explaining that the handler prevents form
submission on Enter when the event target is not an editable element (checks
using e.target.tagName and e.target.isContentEditable), so that inputs,
textareas and contenteditable hosts are allowed to accept Enter while other
elements trigger formik.handleSubmit; ensure the rename is applied where the
variable is declared and used and note in the PR that this change intentionally
excludes contenteditable elements (e.g., the URL editor) from submitting on
Enter.

Comment on lines 319 to 330
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault();
formik.handleSubmit();
if (e.key === 'Enter' && !e.defaultPrevented) {
const isTextInput
= ['input', 'textarea'].includes(e.target.tagName.toLowerCase())
|| e.target.isContentEditable;

if (!isTextInput) {
e.preventDefault();
formik.handleSubmit();
}
}
}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠ïļ Potential issue | ðŸŸĄ Minor

ðŸ§Đ Analysis chain

🏁 Script executed:

# First, let's check the file and surrounding context
head -n 335 packages/bruno-app/src/components/Sidebar/NewRequest/index.js | tail -n 25

Repository: usebruno/bruno

Length of output: 853


🏁 Script executed:

# Search for SingleLineEditor implementation and CodeMirror configuration
fd -e js -e jsx -e ts -e tsx | xargs grep -l 'SingleLineEditor' | head -5

Repository: usebruno/bruno

Length of output: 505


🏁 Script executed:

# Look for CodeMirror keydown/Enter handling
rg -n 'SingleLineEditor|CodeMirror' packages/bruno-app/src/components/Sidebar/NewRequest/index.js -A2 -B2

Repository: usebruno/bruno

Length of output: 576


🏁 Script executed:

# Find SingleLineEditor implementation
fd -type f -name 'SingleLineEditor' -o -path '*/SingleLineEditor/*'

Repository: usebruno/bruno

Length of output: 228


🏁 Script executed:

# Look for SingleLineEditor component definition
rg -n 'export.*SingleLineEditor|const SingleLineEditor' packages/bruno-app/src/components/ -type js -type jsx -type ts -type tsx

Repository: usebruno/bruno

Length of output: 85


🏁 Script executed:

# Search in the most likely location
cat packages/bruno-app/src/components/SingleLineEditor/index.js 2>/dev/null | head -100

Repository: usebruno/bruno

Length of output: 3488


🏁 Script executed:

# Check what props are passed to SingleLineEditor in NewRequest
rg -n -A5 'SingleLineEditor' packages/bruno-app/src/components/Sidebar/NewRequest/index.js | grep -A10 'url'

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Look for the complete SingleLineEditor usage in NewRequest
sed -n '520,540p' packages/bruno-app/src/components/Sidebar/NewRequest/index.js

Repository: usebruno/bruno

Length of output: 979


🏁 Script executed:

# Search for onRun handler in NewRequest component
rg -n 'onRun|handleRun' packages/bruno-app/src/components/Sidebar/NewRequest/index.js

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Check setupAutoComplete implementation to see if it calls preventDefault
rg -n 'setupAutoComplete|preventDefault' packages/bruno-app/src/utils/codemirror/autocomplete.js -A3 -B3 | head -50

Repository: usebruno/bruno

Length of output: 274


🏁 Script executed:

# Also check if variablesAutocomplete prop affects behavior
rg -n 'variablesAutocomplete' packages/bruno-app/src/components/SingleLineEditor/ -A2 -B2

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Search more broadly for autocomplete and preventDefault
rg -n 'preventDefault' packages/bruno-app/src/utils/codemirror/ --type js

Repository: usebruno/bruno

Length of output: 935


🏁 Script executed:

# Check the complete SingleLineEditor props in NewRequest to see if onRun is passed
sed -n '525,545p' packages/bruno-app/src/components/Sidebar/NewRequest/index.js

Repository: usebruno/bruno

Length of output: 979


🏁 Script executed:

# Search for form submission behavior and any other Enter handlers
rg -n 'formik.handleSubmit|onSubmit' packages/bruno-app/src/components/Sidebar/NewRequest/index.js -B2 -A2

Repository: usebruno/bruno

Length of output: 761


🏁 Script executed:

# Check CodeMirror documentation or code to understand if Enter fires preventDefault by default
rg -n 'Enter.*runHandler|extraKeys' packages/bruno-app/src/components/SingleLineEditor/index.js -A5 -B2

Repository: usebruno/bruno

Length of output: 772


🏁 Script executed:

# Verify if SingleLineEditor in NewRequest passes onRun prop
rg -n 'SingleLineEditor' packages/bruno-app/src/components/Sidebar/NewRequest/index.js -A20 | grep -E 'onRun|variablesAutocomplete|/>'

Repository: usebruno/bruno

Length of output: 143


🏁 Script executed:

# Check CodeMirror autocomplete behavior with preventDefault
rg -n 'preventDefault' packages/bruno-app/src/utils/codemirror/autocomplete.js -B5 -A5 | head -40

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Check complete autocomplete implementation for preventDefault
cat packages/bruno-app/src/utils/codemirror/autocomplete.js | head -150

Repository: usebruno/bruno

Length of output: 4400


🏁 Script executed:

# Check if CodeMirror autocomplete widget calls preventDefault
rg -n 'prevented|onKeyDown|ArrowDown|ArrowUp' packages/bruno-app/src/utils/codemirror/autocomplete.js -B2 -A2

Repository: usebruno/bruno

Length of output: 279


🏁 Script executed:

# Check if runHandler in SingleLineEditor calls preventDefault
sed -n '37,50p' packages/bruno-app/src/components/SingleLineEditor/index.js

Repository: usebruno/bruno

Length of output: 438


🏁 Script executed:

# Search for Enter key handling with preventDefault in autocomplete
rg -n 'Enter|keydown' packages/bruno-app/src/utils/codemirror/autocomplete.js -A5 -B5 | head -80

Repository: usebruno/bruno

Length of output: 580


🏁 Script executed:

# Check if there's any widget or menu that handles Enter with preventDefault
rg -n 'widget|menu' packages/bruno-app/src/utils/codemirror/autocomplete.js -B3 -A3

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Look for the complete autocomplete.js to see if it has onKeyDown handlers
wc -l packages/bruno-app/src/utils/codemirror/autocomplete.js

Repository: usebruno/bruno

Length of output: 117


🏁 Script executed:

# Read the autocomplete file to find Enter key handling
sed -n '600,750p' packages/bruno-app/src/utils/codemirror/autocomplete.js | grep -A10 -B10 'Enter\|ArrowDown\|ArrowUp\|keydown\|prevent'

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Check if CodeMirror's hint addon is used
rg -n 'showHints\|hint' packages/bruno-app/src/utils/codemirror/autocomplete.js -B3 -A3 | head -60

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Read middle section of autocomplete file
sed -n '400,500p' packages/bruno-app/src/utils/codemirror/autocomplete.js

Repository: usebruno/bruno

Length of output: 3664


🏁 Script executed:

# Look for hint widget or menu handling
sed -n '650,748p' packages/bruno-app/src/utils/codemirror/autocomplete.js

Repository: usebruno/bruno

Length of output: 2493


🏁 Script executed:

# Check if CodeMirror hint is using the official addon
rg -n 'require.*hint|import.*hint' packages/bruno-app/src/utils/codemirror/

Repository: usebruno/bruno

Length of output: 151


🏁 Script executed:

# Check if CodeMirror's hint addon calls preventDefault during autocomplete selection
rg -n 'show.*hint\|hint.*widget' packages/bruno-app/src/ -l | head -5

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Verify what happens when SingleLineEditor is rendered - check if onRun is essential
sed -n '25,75p' packages/bruno-app/src/components/SingleLineEditor/index.js

Repository: usebruno/bruno

Length of output: 1676


🏁 Script executed:

# Search for any other New Request handlers or Submit buttons
rg -n 'type.*submit\|button.*submit' packages/bruno-app/src/components/Sidebar/NewRequest/index.js -B2 -A2

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Final verification: confirm that SingleLineEditor's Enter key behavior with no onRun passed
sed -n '37,50p' packages/bruno-app/src/components/SingleLineEditor/index.js | grep -A15 "runHandler"

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Check if there's any other place where form submission could happen on Enter
sed -n '300,335p' packages/bruno-app/src/components/Sidebar/NewRequest/index.js

Repository: usebruno/bruno

Length of output: 1197


Rename isTextInput and add explanatory comment per coding guidelines

The variable name isTextInput conflates HTML input/textarea elements with CodeMirror's contenteditable host. Rename to isEditableTarget for clarity.

The handler's logic is non-trivial (preventing form submission when Enter targets non-editable elements) and needs a comment explaining the purpose per coding standards.

Suggested rename + comment
 onKeyDown={(e) => {
   if (e.key === 'Enter' && !e.defaultPrevented) {
-    const isTextInput
-      = ['input', 'textarea'].includes(e.target.tagName.toLowerCase())
-        || e.target.isContentEditable;
+    // Only submit form on Enter if the target is not an editable field
+    // (e.g. avoid submission when Enter is pressed in the URL editor)
+    const isEditableTarget
+      = ['input', 'textarea'].includes(e.target.tagName.toLowerCase())
+        || e.target.isContentEditable;

-    if (!isTextInput) {
+    if (!isEditableTarget) {
       e.preventDefault();
       formik.handleSubmit();
     }
   }
 }}

Note: This change excludes contenteditable elements (like the URL editor) from form submission on Enter, which is a behavior change from the previous implementation. Ensure this is intentional and document in the PR if needed.

ðŸĪ– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/components/Sidebar/NewRequest/index.js` around lines
319 - 330, Rename the local variable isTextInput to isEditableTarget inside the
onKeyDown handler in the NewRequest component, and add a concise inline comment
above the logic explaining that the handler prevents form submission on Enter
when the event target is not an editable element (checks using e.target.tagName
and e.target.isContentEditable), so that inputs, textareas and contenteditable
hosts are allowed to accept Enter while other elements trigger
formik.handleSubmit; ensure the rename is applied where the variable is declared
and used and note in the PR that this change intentionally excludes
contenteditable elements (e.g., the URL editor) from submitting on Enter.

@pooja-bruno

Copy link
Copy Markdown
Collaborator

JIRA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enter on Create New Request modal when creating

3 participants