close
Skip to content

[select] Allow mouse selection without highlight#4699

Merged
atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/select-mouse-selection-without-highlight
May 7, 2026
Merged

[select] Allow mouse selection without highlight#4699
atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/select-mouse-selection-without-highlight

Conversation

@atomiks
Copy link
Copy Markdown
Contributor

@atomiks atomiks commented Apr 28, 2026

Partially addresses #4698
Closes #4663

Mouse selection could become a no-op when a Select item was not highlighted, even if the user clicked or drag-selected the item intentionally. This allows real mouse selection to commit when the press starts on the item, while keeping the guard for alignItemWithTrigger cases where an item appears under the cursor as the popup opens.

This does not claim to fix the underlying [data-highlighted] styling/registration issue; it only prevents mouse selection from bailing when highlight state is unavailable. For #4663, it only addresses pointer selection becoming a no-op; it does not make nested Accordion content a supported Select composition.

Changes

  • Allow real mouse clicks that start on a Select.Item to select even when the item is not highlighted.
  • Allow drag-to-select to commit when highlightItemOnHover is disabled.
  • Preserve the aligned-popup guard that ignores opening clicks that did not start on an item.
  • Add regression tests for unhighlighted mouse clicks, drag-to-select, and the aligned opening-click case.

@atomiks atomiks added component: select Changes related to the select component. type: bug It doesn't behave as expected. labels Apr 28, 2026 — with Image ChatGPT Codex Connector
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 28, 2026

commit: f64bda4

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented Apr 28, 2026

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+45B(+0.01%) 🔺+58B(+0.04%)

Details of bundle changes

Performance

Total duration: 1,144.98 ms ▼-158.45 ms(-12.2%) | Renders: 50 (+0) | Paint: 1,774.50 ms ▼-232.06 ms(-11.6%)

Test Duration Renders
Menu open (500 items) 76.97 ms 🔺+6.11 ms(+8.6%) 12 (+0)
Select open (500 options) 52.36 ms 🔺+2.99 ms(+6.1%) 14 (+0)
Select mount (200 instances) 123.91 ms ▼-49.64 ms(-28.6%) 3 (+0)
Mixed surface mount (app-like density) 64.07 ms ▼-25.52 ms(-28.5%) 5 (+0)
Menu mount (300 instances) 129.50 ms ▼-18.26 ms(-12.4%) 2 (+0)

…and 7 more — details


Check out the code infra dashboard for more information about this PR.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 28, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit f64bda4
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69fc5d3ad0791c000803bd61
😎 Deploy Preview https://deploy-preview-4699--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@rachel-church
Copy link
Copy Markdown

Confirmed that this is a partial fix for #4698. Options can be selected with mouse events, but the hover state does not appear.

Image

@atomiks atomiks marked this pull request as ready for review April 29, 2026 23:55
@atomiks atomiks force-pushed the codex/select-mouse-selection-without-highlight branch 2 times, most recently from 671c159 to 0fa7ad2 Compare May 7, 2026 09:02
@atomiks atomiks force-pushed the codex/select-mouse-selection-without-highlight branch from 0fa7ad2 to f64bda4 Compare May 7, 2026 09:36
Copy link
Copy Markdown
Contributor Author

atomiks commented May 7, 2026

Code Review (GPT-5.5)

Approve ✅ — the branch fixes the unhighlighted mouse-selection regression while preserving the alignItemWithTrigger opening-release guard and the drag-to-select fast path, with focused Select coverage passing in both JSDOM and Chromium.

1. Bugs / Issues (None)

No actionable issues found in the current branch diff.

Root Cause & Patch Assessment

The previous selection guard conflated “this item is highlighted” with “the user intended to select this item.” That broke real mouse selection whenever hover highlighting was disabled or unavailable. The patch now tracks mouse intent separately:

  • real mouse clicks must start on the item via allowMouseSelectionRef
  • drag-to-select still commits through onMouseUp
  • generic virtual clicks remain tied to highlight state
  • virtual clicks carrying pointer metadata can activate unhighlighted items for assistive technology paths
  • opening-release selection is delayed for both selected and unselected items unless real drag movement opts into the unselected mouseup path sooner

Moving the drag accumulator into selectionRef.current.dragY keeps cross-item drag accumulation scoped to one Select root, avoiding module-level shared state across Select instances.

Edge Cases Worth Noting

The small-movement behavior is now covered both ways: a small pointer movement does not unlock the fast drag path before the opening delay, but it also does not permanently block selection after the delay elapses.

The 400ms opening guard is simpler than the previous selected/unselected split and matches the safer behavior for cases where the popup opens under a neighboring item rather than the selected item.

Test Coverage Assessment

The added tests cover the main regression and adjacent guardrails:

  • unhighlighted mouse click selection
  • generic virtual click rejection when unhighlighted
  • opening-release guard for unselected items
  • fast drag-to-select before the delay
  • accumulated drag movement across items
  • drag-to-select with hover highlighting disabled
  • small pointer movement not counting as drag
  • small pointer movement still selecting after the delay
  • opening click that did not start on the item being ignored

Validation run on the final squashed branch:

pnpm prettier
git diff --check
pnpm test:jsdom SelectItem --no-watch
pnpm test:chromium SelectItem --no-watch
pnpm test:jsdom SelectRoot --no-watch
pnpm test:chromium SelectRoot --no-watch
pnpm typescript
pnpm size:snapshot

The regression tests were not run against upstream/master; their upstream failure is by inspection from the old !highlighted guard.

@atomiks atomiks merged commit 110c787 into mui:master May 7, 2026
23 checks passed
@atomiks atomiks deleted the codex/select-mouse-selection-without-highlight branch May 7, 2026 10:05
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. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[select][Accordion] Select.Item in Accordion.Panel is not clickable after v1.4.0

2 participants