Skip to content

[select] Fire onClick during drag-to-select - #3968

Closed
obeattie wants to merge 1 commit into
mui:masterfrom
obeattie:fix/select-drag-to-select-onclick
Closed

obeattie wants to merge 1 commit into
mui:masterfrom
obeattie:fix/select-drag-to-select-onclick

Conversation

@obeattie

@obeattie obeattie commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

The drag-to-select behavior which was originally introduced in #541 (mousedown on trigger → drag to item → mouseup to select) bypasses the item's onClick handler since the browser doesn't fire a click event when mousedown and mouseup occur on different elements. This is inconsistent with the other ways to select an item: both regular clicks and keyboard selection both invoke onClick already.

This PR calls onClick from onMouseUp before committing the selection, allowing preventBaseUIHandler() to cancel the selection.

Includes tests.

@pkg-pr-new

pkg-pr-new Bot commented Feb 4, 2026

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3968
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3968
    

commit: 1a03fd5

@netlify

netlify Bot commented Feb 4, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 1a03fd5
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69835bf07d691c0008707ac1
😎 Deploy Preview https://deploy-preview-3968--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps

greptile-apps Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Ensures onClick handler is invoked consistently across all selection methods (regular clicks, keyboard selection, and drag-to-select).

Key Changes:

  • Modified onMouseUp handler in SelectItem.tsx to call user's onClick prop before committing selection during drag-to-select
  • Added makeEventPreventable to allow onClick handlers to cancel selection via preventBaseUIHandler()
  • Imported required types (BaseUIEvent) and utilities (makeEventPreventable)

Test Coverage:

  • Added test verifying onClick is called during drag-to-select
  • Added test verifying selection can be prevented via preventBaseUIHandler() in onClick

The implementation correctly mirrors the behavior of regular clicks and keyboard selection, both of which already invoke onClick and respect preventBaseUIHandler().

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-designed and consistent with existing patterns. The implementation uses the same makeEventPreventable pattern already used throughout the codebase. Comprehensive tests cover both the happy path and the prevention path. The change makes drag-to-select behavior consistent with regular clicks and keyboard selection.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/select/item/SelectItem.tsx Added onClick handler invocation in onMouseUp for drag-to-select consistency with regular clicks and keyboard selection
packages/react/src/select/item/SelectItem.test.tsx Added comprehensive tests for onClick behavior during drag-to-select with and without preventBaseUIHandler

@obeattie obeattie closed this Feb 4, 2026
@zannager zannager added the component: select Changes related to the select component. label Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: select Changes related to the select component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants