theKashey / react-focus-lock

It is a trap! A lock for a Focus. 🔓
MIT License
1.27k stars 67 forks source link

FocusLock autoFocus={false} not working when outside component do ref.focus #204

Closed Bruceeeeeee closed 1 year ago

Bruceeeeeee commented 2 years ago

In my case we use FocusLock and AutoFocusInside for dialog. `

xxx

` in some cases like opening dialog by clicking the dropdown menu item, while the dialog is rendering, menu will also do some sth like ref.focus. In this case, autoFocus={false} not working, it will still focus the first available element.

I tried the disabled props in AutoFocusInside, also not working

theKashey commented 2 years ago

Can you clarify the desired behavior? You've provided some information about how it is not working, but how it should work?

Bruceeeeeee commented 2 years ago

Hi, I think the desired behavior should be when we set autoFocus=false, it shouldn't focus automatically even the focus is outside the lock. To implement this behavior, maybe there could be a 'disabled' props for AutoFocusInside to disable the initial auto focus?

theKashey commented 2 years ago

No, this is not how Lock works:

autofocus controls only what will be focused. Without it enabled you are expected to do something onActivation, and FocusLock will not interfere.

stale[bot] commented 1 year ago

This issue has been marked as "stale" because there has been no activity for 2 months. If you have any new information or would like to continue the discussion, please feel free to do so. If this issue got buried among other tasks, maybe this message will reignite the conversation. Otherwise, this issue will be closed in 7 days. Thank you for your contributions so far.