Autocomplete input focus is inconsistent
Provide a general summary of the issue here
Autocomplete input focus is inconsistent. Sometimes clicking the input field adds data-focused="true" attribute, sometimes it doesn't.
๐ค Expected Behavior?
data-focused="true" should be consistently added to input on input click
๐ฏ Current Behavior
After hovering any option, clicking the input field doesn't focus it until a key is pressed. After pressing a key, the input field can again be focused until any option is hovered
๐ Possible Solution
No response
๐ฆ Context
No response
๐ฅ๏ธ Steps to Reproduce
visit autocomplete's storybook Path 1: click the input field without hovering any option - it becomes focused hover any option - option becomes focused. Input field loses focus and is unable to be focused until any keypress is provided to the input Path 2: hover any option - both Input field and option become focused click out of the autocomplete box - both lose the focus. Input field is unable to be focused until any keypress is provided to the input
the same behavior occurs in docs
Version
react-aria-components: "1.8.0"
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
mac
๐งข Your Company/Team
No response
๐ท Tracking Issue
No response
Seems to be a bug in how we handle the virtual focus between the input and the items in the list. We dispatch virtual blur events between the input and the items in the list in an effort to make sure only one or the other has visible focus but that inadvertently causes the input field to lose isFocused rather than just isFocusVisible when the item is focused (in this case via hover). We could opt for including custom information in the dispatched events perhaps to inform useFocusRing that it should be changing isFocusVisible instead
I want to propose using RAC for more complex interactions at work but I already see the complaints from product and design coming about the input loosing visual focus due to isFocused not being true. Is this bug still on your radar? Could I help with a fix somehow?
You're more than welcome to submit a PR for consideration. It looks like @LFDanLu had a suggestion for a route to try, I'd start there and we'll see what falls out of it. Thank you!!
I looked into this and it seems to come from virtual focus not being cleared when the input is already active. I have a small fix and tests ready locally, and can open a PR
@hanityx sure go for it!