react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

Autocomplete input focus is inconsistent

Open Szulerinio opened this issue 1 year ago โ€ข 5 comments

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

Szulerinio avatar May 06 '25 21:05 Szulerinio

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

LFDanLu avatar May 07 '25 22:05 LFDanLu

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?

levrik avatar Feb 14 '26 19:02 levrik

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!!

snowystinger avatar Feb 16 '26 00:02 snowystinger

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 avatar Mar 09 '26 16:03 hanityx

@hanityx sure go for it!

LFDanLu avatar Mar 09 '26 17:03 LFDanLu