react-spatial-navigation icon indicating copy to clipboard operation
react-spatial-navigation copied to clipboard

Should components be focusable via setFocus() when focusable={false}?

Open shirakaba opened this issue 6 years ago • 0 comments

There are two scenarios here:

  1. Directly focusing via setFocus() (a focus "teleport")
  2. Shifting focus via the directional keys (a focus "shift")

At the minimum, components with focusable={false} should not be focusable by shifting focus (which is the case right now).

It's less clear what the sensible behaviour should be for direct focus. As of 2.7.2, focusable={false} components can be focused by a direct call to setFocus().

From my view, if a component is marked as focusable={false}, it should not be focusable under any circumstances. It probably has that property set because: it's off-screen or invisible; or needs to be left disabled due to a request being in-flight, or due to a privilege being inactive. There is a chance of the app entering an illegal state if an unexpected async action leads to a focusable={false} component gaining focus via a focus teleport.

But I can also see that setFocus() should reliably do its job of setting the focus (as advertised).

Is there perhaps a need for a distinction:

  1. focusable={false} – cannot be focused by a focus shift, nor by a focus teleport.
  2. navigable={false} – cannot be focused by a focus shift, but can be focused by a focus teleport.

Naming of course can be improved upon.

... Or an init-level option e.g. setFocusRespectsFocusableValue: true.

shirakaba avatar Aug 02 '19 10:08 shirakaba