Repository navigation
fix: don't open the menu if the input lost focus before the open finished - #6107
Open
balajis-qb wants to merge 1 commit into
Open
balajis-qb wants to merge 1 commit into
balajis-qb wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 9000a51 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
If a parent moves focus away during mousedown, the input blurs before the queued "open menu" step runs. The menu then opened with nothing focused, so an outside click could never close it and onBlur never fired again. openMenu() now calls onMenuOpen() only if the select is still focused. Fixes JedWatson#6098
balajis-qb
force-pushed
the
fix/issue-6098/menu-open-after-focus-lost
branch
from
October 20, 2026 12:41
c1c971a to
9000a51
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue: #6098
Problem
If a parent element moves focus away from the select during
mousedown(for example
onMouseDown={() => ref.current?.focus()}), the eventshappened in this order:
onBlurandonMenuCloseran.setStatecallback.The menu ended up open, but the input no longer had focus. A click outside
could not blur it again, so
onBlurnever fired and the menu never closed.The fix
In
openMenu(), thesetStatecallback now callsonMenuOpen()only ifthis.state.isFocusedis still true. If focus was lost in the meantime,the late "open" is skipped, so the select ends up closed and blurred.
Behaviour change to be aware of
In this focus-stealing setup the menu will no longer open on click. Before,
it opened but was unusable by keyboard and could not be closed by an outside
click. If you would rather keep the old behaviour, I am happy to try another
approach.
Alternative: workaround without changing the library
If this behaviour change is not wanted, the app can avoid the problem itself.
The cause is the parent calling
focus()on every click, including clicks thatcome from inside the select. Only steal focus for clicks on the parent itself:
If the maintainers prefer this answer, this PR can be closed.
Tests
Added a regression test to
StateManaged.test.tsx: a select inside a parentthat focuses itself on
mousedown. It checks thatonBlurfires once and themenu is closed. The test fails without the fix. All existing Jest suites pass.
Changeset
Added a patch changeset for
react-select.