Autocomplete: use blur relatedTarget to control menu visibility#8206
Draft
iansan5653 with Copilot wants to merge 2 commits into
Draft
Autocomplete: use blur relatedTarget to control menu visibility#8206iansan5653 with Copilot wants to merge 2 commits into
relatedTarget to control menu visibility#8206iansan5653 with Copilot wants to merge 2 commits into
Conversation
Co-authored-by: iansan5653 <2294248+iansan5653@users.noreply.github.com>
Co-authored-by: iansan5653 <2294248+iansan5653@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 64f9a95 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 |
Copilot created this pull request from a session on behalf of
iansan5653
July 21, 2026 14:40
View session
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.
Split out from #7644 (see thread) so it can ship independently of the wider
useProvidedRefOrCreate→useMergedRefsrefactor.AutocompleteInput's blur handler decided whether to close the menu by comparingdocument.activeElementagainst the input's ref. That inference can't distinguish "focused, then focus moved away" from "never focused", and it depends on how the input's ref is wired up — so migratingTextInputto merged refs (in #7644) breaks the blur logic.The handler now reads the blur event's
relatedTargetto detect whether focus is moving into the menu, closing the menu only when it isn't. This tracks the actual focus transition rather than post-interaction DOM state, and is independent of the ref setup.Changelog
New
Changed
Autocomplete: input blur handler uses the blur event'srelatedTargetto decide whether to close the menu.Removed
document.activeElement/inputReffor blur-driven menu dismissal.Rollout strategy
Testing & Reviewing
Run
npx vitest run packages/react/src/Autocomplete/Autocomplete.test.tsx. The new "keeps the menu open when focus moves into the menu" test exercises therelatedTargetpath. Note: browser-mode synthetic focus makes a strict old-vs-new discriminator unreliable (the fragility called out in the source thread), so the test locks in the intendedrelatedTargetcontract rather than reproducing the original failure.