Safer focus lost behavior #2959
Labels
Deliverable
Major item tracked for top-level planning in ADO
enhancement
Needs: Dev Design
Needs: PM Design
New feature or request
Recommend: Not Planned
Recommend that issue should be given Not Planned milestone.
Milestone
Proposal: Safer focus lost behavior
Summary
In Xaml, when the focused control is removed from the visual tree, focus moves to the first element in the window. This differs from other platforms (I don't know how each works, but Xaml seems uniquely extreme in this) - I believe most platforms will find the nearest focusable element or at least keep focus in the same 'window' if focus was in a flyout or subwindow.
Motivation
We have had multiple bugs in our current usage of RNW where a render() update removes the focused element. We've had to add code outside of RNW to notice when this is happening and restore focus back into the RNW control.
vnext's 'safe harbor' feature which when calling blur() will move focus to the root of the reactcontrol is perhaps part of a solution - if it also worked to safe harbor within the nearest 'window' and not just the root. Requiring the call to blur() is also a problem though if its not needed on other platforms. react-native developers on other platforms are unlikely to be aware of this Xaml behavior and some kind of 'auto-blur' behavior on removal seems desirable.
Basic example
Have a RN layout where a Touchable's onPress will re-render and create a different tree with different buttons. Focus will jump to the root of the window. If doing this in a flyout, focus jumps all the way to parent window root.
Open Questions
I attempted to start implementing this just using the current safe harbor, by checking if the current view being removed is the focused element.
The text was updated successfully, but these errors were encountered: