Skip to content

fix: restrict keyboard event handling to modal elements only#6408

Merged
bijin-bruno merged 2 commits intousebruno:mainfrom
Pragadesh-45:fix/valid-prompt-inputs
Dec 19, 2025
Merged

fix: restrict keyboard event handling to modal elements only#6408
bijin-bruno merged 2 commits intousebruno:mainfrom
Pragadesh-45:fix/valid-prompt-inputs

Conversation

@Pragadesh-45
Copy link
Contributor

@Pragadesh-45 Pragadesh-45 commented Dec 15, 2025

Description

This update refines the keyboard event handling logic by restricting it to modal elements only. Previously, keyboard events may have been triggered globally, which could interfere with other UI elements outside of modals. With this change, keyboard event listeners will only be active within modal contexts, ensuring better user experience and avoiding unintended interactions.

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.

Summary by CodeRabbit

  • Bug Fixes
    • Modal keyboard handling tightened: non-ESC keys are now processed only when the interaction target is inside the modal, preventing outside key events from affecting it. ESC behavior remains unchanged; Enter/submit still triggers when the event target is within the modal.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

Walkthrough

The Modal component's document-level keydown handler now ignores non-ESC keys when the event target is outside the modal; ESC handling remains global. Enter/submit behavior is preserved but only triggers when the key event originates from inside the modal.

Changes

Cohort / File(s) Summary
Modal keydown handler guard
packages/bruno-app/src/components/Modal/index.js
Added a guard to the document keydown handler so non-ESC key events are processed only if event.target is inside the modal; ESC handling remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5–10 minutes

  • Verify the DOM containment check (e.g., contains or similar) correctly identifies elements inside the modal.
  • Confirm ESC key handling path is unchanged and still works from outside the modal.
  • Check behavior with nested or dynamically mounted modal content.

Possibly related PRs

  • PR #6356 – Modifies Modal's document-level keydown handler with event.target-based logic; directly related to this PR's approach of conditioning key handling on event source.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno

Poem

Keys tap softly at the frame,
Only those within may play the game,
ESC still flies across the hall,
Enter listens when inside the wall,
Modal gates keep focus bright — hooray! 🚪✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: restricting keyboard event handling to modal elements only, which aligns with the primary modification in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b4c130 and 1ccee90.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/Modal/index.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-app/src/components/Modal/index.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: CLI Tests
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: Unit Tests
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - macOS

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/bruno-app/src/components/Modal/index.js (1)

83-112: Enter key handler correctly respects disabled state; align useEffect deps with confirmDisabled

The added !confirmDisabled guard is the right move and keeps keyboard confirm behavior consistent with the disabled button state. One follow‑up: handleKeydown now depends on confirmDisabled, but confirmDisabled is not in the useEffect dependency array. If a modal uses a stable handleConfirm while toggling confirmDisabled during its lifetime, the keydown listener could keep a stale confirmDisabled and still fire (or never fire) on Enter.

You can keep the behavior robust by including confirmDisabled in the deps so the listener is re‑bound when it changes:

-  useEffect(() => {
-    document.addEventListener('keydown', handleKeydown, false);
-    return () => {
-      document.removeEventListener('keydown', handleKeydown);
-    };
-  }, [disableEscapeKey, document, handleConfirm]);
+  useEffect(() => {
+    document.addEventListener('keydown', handleKeydown, false);
+    return () => {
+      document.removeEventListener('keydown', handleKeydown);
+    };
+  }, [disableEscapeKey, handleConfirm, confirmDisabled]);
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c11266a and 35e305c.

📒 Files selected for processing (2)
  • packages/bruno-app/src/components/Modal/index.js (1 hunks)
  • packages/bruno-app/src/components/RequestPane/PromptVariables/PromptVariablesModal/index.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/components/RequestPane/PromptVariables/PromptVariablesModal/index.js
  • packages/bruno-app/src/components/Modal/index.js
🧬 Code graph analysis (1)
packages/bruno-app/src/components/Modal/index.js (1)
packages/bruno-app/src/components/ResponseExample/CreateExampleModal/index.js (1)
  • handleConfirm (18-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: CLI Tests
  • GitHub Check: Unit Tests
  • GitHub Check: SSL Tests - Linux
🔇 Additional comments (1)
packages/bruno-app/src/components/RequestPane/PromptVariables/PromptVariablesModal/index.js (1)

18-34: Prompt validation and confirmDisabled wiring look solid

The allFilled computation with a trimmed non‑empty check, combined with confirmDisabled={!allFilled}, cleanly prevents submitting when any prompt is blank and keeps the modal confirm button and Enter‑key behavior in sync with the required inputs. This aligns well with the PR’s goal of avoiding empty prompt values being sent from the URL bar.

@Pragadesh-45 Pragadesh-45 marked this pull request as draft December 15, 2025 12:34
@Pragadesh-45 Pragadesh-45 force-pushed the fix/valid-prompt-inputs branch from 35e305c to 116672a Compare December 16, 2025 07:25
@Pragadesh-45 Pragadesh-45 changed the title fix: enhance modal confirmation handling and validate prompt inputs fix: restrict keyboard event handling to modal elements only Dec 16, 2025
@Pragadesh-45 Pragadesh-45 force-pushed the fix/valid-prompt-inputs branch from 116672a to 9b4c130 Compare December 16, 2025 13:08
@Pragadesh-45 Pragadesh-45 marked this pull request as ready for review December 19, 2025 08:49
@bijin-bruno bijin-bruno merged commit 41efa85 into usebruno:main Dec 19, 2025
7 of 8 checks passed
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.

2 participants