Skip to content

Autocomplete: option for disabling auto-focus of search field? #8160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jeffijoe opened this issue Apr 29, 2025 · 4 comments
Open

Autocomplete: option for disabling auto-focus of search field? #8160

jeffijoe opened this issue Apr 29, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@jeffijoe
Copy link
Contributor

Provide a general summary of the feature here

I'd like a prop for Autocomplete that turns off the automatic focusing of the search field when interacting with items.

🤔 Expected Behavior?

When the new prop disableAutoFocusOnItemInteraction (name tbd 😅 ) is true, interacting with items in the list will not trigger focus on the search field. However, if the search field is already focused, then the focus will be maintained.

😯 Current Behavior

Currently, any interaction with the items triggers focus on the search field. This causes the soft keyboard on mobile devices to appear, which is unexpected.

💁 Possible Solution

No response

🔦 Context

I'm using autocomplete inside of a modal. Since I'm animating the modal in with a slide-in animation using motion/react, the auto-focus behavior breaks the visual viewport adjustment that react-aria makes to fit the dialog within the viewport. Additionally, with auto-focus, the keyboard cannot be dismissed on iOS (this appears to be a general bug).

focus-issue-encoded.mp4

As a workaround, I decided to disable autoFocus on the search field for the autocomplete. However, now, when the user interacts with an item that is halfway down the visible viewport, the keyboard opens and covers the item that the user interacted with.

autofocus-autocomplete-encoded.mp4

💻 Examples

No response

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@LFDanLu
Copy link
Member

LFDanLu commented Apr 30, 2025

This seems reasonable, but we'd like it not to be a prop. Perhaps this virtual focus behavior should be based on modality instead, aka perhaps we disable it for modalities other than keyboard. Will have to play around with the experience to see how it feels though

@LFDanLu LFDanLu added the bug Something isn't working label Apr 30, 2025
@jeffijoe
Copy link
Contributor Author

jeffijoe commented May 1, 2025

So we're saying only trigger actual focus (which in turn would trigger the soft keyboard) when using the keyboard for navigation? That would make sense to me, assuming we can still auto-focus for hardware keyboard users?

@LFDanLu
Copy link
Member

LFDanLu commented May 1, 2025

Right, if we turn off virtual focus for modalities other than keyboard, theoretically the search field and the associated wrapped collection will simply behave as two separate tabbable entities.

@devongovett
Copy link
Member

Basically we'd need to add a touch interaction check here

if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current) {
inputRef.current.focus();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🩺 To Triage
Development

No branches or pull requests

3 participants