Skip to content

fix(SelectTrigger): prevent supression of mousedown event#2688

Open
rastuhacode wants to merge 2 commits into
unovue:v2from
rastuhacode:fix/not-supress-select-mousedown-1773
Open

fix(SelectTrigger): prevent supression of mousedown event#2688
rastuhacode wants to merge 2 commits into
unovue:v2from
rastuhacode:fix/not-supress-select-mousedown-1773

Conversation

@rastuhacode

@rastuhacode rastuhacode commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #1773

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Issue

SelectTrigger opens the select on pointerdown and was calling event.preventDefault() there to stop the trigger from taking focus away from the highlighted item in the listbox.

Per the Pointer Events spec, calling preventDefault() on pointerdown cancels the compatibility mouse events that follow — mousedown, mouseup, and click.

Fix

Focus prevention was moved from pointerdown to mousedown:

  • pointerdown — still opens the select, but no longer calls preventDefault(), so the browser emits mousedown.
  • mousedown — calls preventDefault() under the same conditions (left click, no Ctrl) to keep the trigger from stealing focus.

Global mousedown listeners (including capture-phase ones on window) now fire before the trigger’s own mousedown handler runs.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Select component's click handling to better support control-key interactions.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

SelectTrigger.vue adds a shared helper isCtrlLeftClick(event) that checks for left-button interaction without Ctrl, and refactors the @pointerdown and @mousedown handlers to conditionally gate handlePointerOpen() and preventDefault() behind this helper, restoring event propagation to window-level listeners.

Changes

Select trigger click handling refactor

Layer / File(s) Summary
Click filter helper and refactored handlers
packages/core/src/Select/SelectTrigger.vue
isCtrlLeftClick() helper function checks for left-button clicks without Ctrl key. Both @pointerdown and @mousedown handlers now use this helper to conditionally call handlePointerOpen() and prevent default, replacing inline checks and allowing external window listeners to execute. Comment updated to reflect the new gating logic.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🐰 A select that plays nice and shares,
Lets other listeners have their fairs,
No more capturing every click with glee,
Just left-clicks rule, so frameworks run free!

🚥 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 suppression of mousedown events in SelectTrigger, which is the core change in this PR.
Linked Issues check ✅ Passed The PR successfully addresses issue #1773 by moving preventDefault() from pointerdown to mousedown, allowing window-level mousedown listeners to fire while maintaining focus-prevention behavior.
Out of Scope Changes check ✅ Passed All changes are within scope: they implement the solution described in the PR objectives by extracting the condition into a helper function and adjusting event handling logic.
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 unit tests (beta)
  • Create PR with unit tests

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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/reka-ui@2688

commit: 8ed0a48

@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.

🧹 Nitpick comments (1)
packages/core/src/Select/SelectTrigger.vue (1)

107-116: ⚡ Quick win

Add a regression test for window-level mousedown propagation.

This change fixes a cross-framework integration path, but provided test context only shows open-on-pointerdown behavior. Please add/extend a test to assert a window (including capture-phase) mousedown listener still fires when clicking SelectTrigger.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/Select/SelectTrigger.vue` around lines 107 - 116, Extend
the test suite for SelectTrigger to add a regression test that verifies a
window-level mousedown listener (including capture phase) is still invoked when
clicking the SelectTrigger component; specifically, render the SelectTrigger (or
the parent Select component) in the test, attach a spy listener to
window.addEventListener('mousedown', handler, { capture: true }) and ensure the
handler is called after dispatching a click/mousedown on the SelectTrigger
element, and include a case that covers the new inline mousedown handler which
conditionally calls event.preventDefault() via isCtrlLeftClick so the test
proves propagation to window is preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/core/src/Select/SelectTrigger.vue`:
- Around line 107-116: Extend the test suite for SelectTrigger to add a
regression test that verifies a window-level mousedown listener (including
capture phase) is still invoked when clicking the SelectTrigger component;
specifically, render the SelectTrigger (or the parent Select component) in the
test, attach a spy listener to window.addEventListener('mousedown', handler, {
capture: true }) and ensure the handler is called after dispatching a
click/mousedown on the SelectTrigger element, and include a case that covers the
new inline mousedown handler which conditionally calls event.preventDefault()
via isCtrlLeftClick so the test proves propagation to window is preserved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb61f0eb-7c2f-4c3b-b169-42c0e16dd590

📥 Commits

Reviewing files that changed from the base of the PR and between bb0c552 and 8ed0a48.

📒 Files selected for processing (1)
  • packages/core/src/Select/SelectTrigger.vue

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.

[Bug]: SelectTrigger captures clicks so that event listeners on window don't run, breaking other frameworks.

1 participant