Hey @theKashey, I am looking at adding support for focus options when calling .focus() in returnFocus.
See here: https://github.com/theKashey/react-focus-lock/blob/master/src/Lock.js#L60
The reason for that is that currently when the focus gets returned, if the page has been scrolled down and the element supposed to receive the focus back is not in view anymore, the browser will scroll to reveal that element being focused.
I understand that setting the returning the focus is absolutely important for accessibility and I wouldn't change that. However, it can be a bit disorientating for users to be scrolled to a difference place for what seems to be no apparent reason (to them).
Most latest browsers actually support an option to disable that behaviour if needed.
See the preventScroll option (false by default) on mdn.
Here's the current support for it.
I think support is not too much of an issue as this can be seen as an enhancement anyway.
I actually need this feature as part of react-focus-on but I know the code for the returnFocus handler actually lives in react-focus-lock.
Would you be willing to add a new prop returnFocusOptions to support that optional behaviour?
If so, I can draft you a PR today.
Let me know!
✌️
Hey @theKashey, I am looking at adding support for focus options when calling
.focus()inreturnFocus.See here: https://github.com/theKashey/react-focus-lock/blob/master/src/Lock.js#L60
The reason for that is that currently when the focus gets returned, if the page has been scrolled down and the element supposed to receive the focus back is not in view anymore, the browser will scroll to reveal that element being focused.
I understand that setting the returning the focus is absolutely important for accessibility and I wouldn't change that. However, it can be a bit disorientating for users to be scrolled to a difference place for what seems to be no apparent reason (to them).
Most latest browsers actually support an option to disable that behaviour if needed.
See the
preventScrolloption (falseby default) on mdn.Here's the current support for it.
I think support is not too much of an issue as this can be seen as an enhancement anyway.
I actually need this feature as part of
react-focus-onbut I know the code for thereturnFocushandler actually lives inreact-focus-lock.Would you be willing to add a new prop
returnFocusOptionsto support that optional behaviour?If so, I can draft you a PR today.
Let me know!
✌️