Skip to content

[select][combobox] Do not trigger Field onBlur handlers when opening popup - #3609

Merged
atomiks merged 3 commits into
mui:masterfrom
atomiks:fix/test-select-act-warnings
Jan 14, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
atomiks:fix/test-select-act-warnings

Conversation

@atomiks

@atomiks atomiks commented Dec 24, 2025 •

Copy link
Copy Markdown
Contributor

focused/touched states/onBlur validation shouldn't run when e.g. clicking the trigger and focus moves into the popup. In that case onBlur runs, but it should really only run when blur leaves the trigger not as the result of opening the popup.

This also addresses act() warnings, since enqueueFocus in FloatingFocusManager is (intentionally) async: clicking the trigger causes focus to move into the popup async, which then fires onBlur, causing the state updates to happen outside act(...)

@atomiks atomiks added component: select Changes related to the select component. test labels Dec 24, 2025
@pkg-pr-new

pkg-pr-new Bot commented Dec 24, 2025 •

Copy link
Copy Markdown
  • vite-css-base-ui-example

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

commit: 346ba82

@mui-bot

mui-bot commented Dec 24, 2025 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+360B(+0.09%) 🔺+195B(+0.15%)

Details of bundle changes


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

@netlify

netlify Bot commented Dec 24, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 346ba82
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/696776993e1bc800086600ad
😎 Deploy Preview https://deploy-preview-3609--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.

@atomiks
atomiks force-pushed the fix/test-select-act-warnings branch 2 times, most recently from 530e23f to f9222e8 Compare December 24, 2025 08:27
@atomiks atomiks added the type: bug It doesn't behave as expected. label Dec 24, 2025
@atomiks atomiks changed the title [select][test] Fix act warnings when wrapped in Field [select][test] Do not trigger Field onBlur handlers when opening popup Dec 24, 2025
@atomiks
atomiks marked this pull request as ready for review December 24, 2025 08:31

@mnajdova mnajdova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, let's add test, unless some commits are missing :)

@atomiks
atomiks force-pushed the fix/test-select-act-warnings branch 2 times, most recently from 01f7837 to a0e5e83 Compare December 29, 2025 05:55
@atomiks atomiks mentioned this pull request Jan 13, 2026
1 task done
@atomiks
atomiks force-pushed the fix/test-select-act-warnings branch from 4aafa25 to 2b9afda Compare January 14, 2026 09:26
@atomiks atomiks changed the title [select][test] Do not trigger Field onBlur handlers when opening popup [select][combobox] Do not trigger Field onBlur handlers when opening popup Jan 14, 2026
@atomiks atomiks self-assigned this Jan 14, 2026
@atomiks atomiks added component: combobox Changes related to the combobox component. and removed test labels Jan 14, 2026
@atomiks
atomiks force-pushed the fix/test-select-act-warnings branch from 2b9afda to fbd4c6f Compare January 14, 2026 09:27
@atomiks

atomiks commented Jan 14, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR prevents Field onBlur handlers and validation from triggering prematurely when opening Select/Combobox popups. Previously, when clicking the trigger to open the popup, focus would move asynchronously into the popup (due to Floating UI's enqueueFocus), causing the trigger's onBlur to fire and marking the field as "touched" even though focus remained within the component.

Changes:

  • Trigger components now check if focus is moving into the popup (contains(positionerElement, event.relatedTarget)) and skip Field blur handling in those cases
  • Root components handle Field blur/validation when the popup closes via focusOut or outsidePress reasons
  • SelectTrigger's onFocus handler now uses REASONS.none instead of REASONS.focusOut when closing due to alignItemWithTriggerActiveRef
  • Test coverage added to verify Field validation only runs when the popup fully blurs to outside elements
  • Also fixes act() warnings caused by async focus updates triggering state changes outside act(...)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-tested with comprehensive test coverage, follow established patterns in the codebase, and address a legitimate UX issue where Field validation was incorrectly triggering when opening popups. The logic correctly distinguishes between blur events that should trigger validation (leaving the component entirely) vs those that shouldn't (moving focus from trigger to popup within the same component).
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/select/trigger/SelectTrigger.tsx Added blur prevention when focus moves into popup, changed onFocus reason from focusOut to none when popup obscures trigger
packages/react/src/select/root/SelectRoot.tsx Added Field blur/validation handling in setOpen callback for focusOut and outsidePress reasons
packages/react/src/combobox/trigger/ComboboxTrigger.tsx Added blur prevention when focus moves into popup using contains check on positionerElement
packages/react/src/combobox/root/AriaCombobox.tsx Added Field blur/validation handling in setOpen callback for inputInsidePopup mode with focusOut and outsidePress reasons

Sequence Diagram

sequenceDiagram
    participant User
    participant Trigger
    participant Field
    participant Popup
    participant FloatingUI

    Note over User,FloatingUI: Before this PR (incorrect behavior)
    User->>Trigger: Click to open
    Trigger->>Field: onFocus
    Field->>Field: setFocused(true)
    Trigger->>FloatingUI: Request open popup
    FloatingUI-->>Popup: Open popup
    FloatingUI->>Popup: enqueueFocus (async)
    Trigger->>Field: onBlur (relatedTarget: popup)
    Field->>Field: setTouched(true), setFocused(false)
    Field->>Field: Validate (onBlur mode) ❌
    Note right of Field: Wrong! Should not validate yet

    Note over User,FloatingUI: After this PR (correct behavior)
    User->>Trigger: Click to open
    Trigger->>Field: onFocus
    Field->>Field: setFocused(true)
    Trigger->>FloatingUI: Request open popup
    FloatingUI-->>Popup: Open popup
    FloatingUI->>Popup: enqueueFocus (async)
    Trigger->>Trigger: onBlur (relatedTarget: popup)
    Trigger->>Trigger: Check contains(popup, relatedTarget) ✓
    Note right of Trigger: Skip Field blur - still in component
    
    Note over User,FloatingUI: Closing popup by clicking outside
    User->>User: Click outside element
    Popup->>FloatingUI: Detect outside press
    FloatingUI->>Popup: setOpen(false, reason: outsidePress)
    Popup->>Field: setTouched(true), setFocused(false)
    Field->>Field: Validate (onBlur mode) ✓
    Note right of Field: Correct! Now validates
Loading

@atomiks
atomiks force-pushed the fix/test-select-act-warnings branch from fbd4c6f to 346ba82 Compare January 14, 2026 10:57
@atomiks
atomiks merged commit 31d35bf into mui:master Jan 14, 2026
@atomiks
atomiks deleted the fix/test-select-act-warnings branch January 14, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: combobox Changes related to the combobox component. 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.

4 participants