The use case I am trying to provide is, by default let your library handle the return focus, but if the user passes a custom ref to focus when the modal gets close, focus on that instead.
The issue is that for this to work, I have to write my ref.focus() in something like setImmediate or requestAnimationFrame to wait for the normal returnToFocus to do its thing first (I'm doing this in onDeactivation callback). Instead I would like to set returnToFocus={false} when a custom ref is passed into my component.
I hope this make sense.
I tested it with react-focus-lock and it worked well by setting returnToFocus={false} and focusing my own thing using onDeactivation callback.
Hi,
First, thanks for this great library. I was wondering why
returnToFocus
was hardcoded as true and not passed as an option toFocusLock
like the others. (see https://github.com/theKashey/react-focus-on/blob/master/src/UI.tsx#L37)The use case I am trying to provide is, by default let your library handle the return focus, but if the user passes a custom ref to focus when the modal gets close, focus on that instead.
The issue is that for this to work, I have to write my
ref.focus()
in something likesetImmediate
orrequestAnimationFrame
to wait for the normalreturnToFocus
to do its thing first (I'm doing this inonDeactivation
callback). Instead I would like to setreturnToFocus={false}
when a custom ref is passed into my component.I hope this make sense. I tested it with
react-focus-lock
and it worked well by settingreturnToFocus={false}
and focusing my own thing usingonDeactivation
callback.Thanks 🙏