You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm in the middle of a rewrite that should get away from the reliance on React context for the focus state updates and use subscriptions to FocusManager to propagate the updates surgically only to the components that actually have their focus state changed, thus reducing the amount of unnecessary re-rendering.
While working on it, I've changed some user-facing TypeScript types so I would also like to use this opportunity to change the API slightly so it's clearer and more cohesive.
Problem
This RFC seeks feedback for the proposed API and the use-cases that might not work nicely with it.
Core API
FocusManager
FocusManager is a React-agnostic class that knows how to move focus between the focusable tree nodes in response to the calls to its methods, it maintains the current focus path - path to the focused leaf node in the tree - and can be subscribed to to receive notifications when that path changes.
It has to be instantiated by the user and the user needs to decide what events should trigger the navigation methods, it can be anything from the regular key presses to the browser Gamepad API events or even scroll.
Root, (formerly SunbeamProvider) is the root focusable component. It instantiates the focusable tree and holds its root node as well as passing FocusManager and some other utilities through the React context to other focusable components in the tree.
This is the part of the API that I expect to be used the most. It can be used both for creating a leaf node or a branch node. If the latter is the goal the node has to be passed down the tree through the React context, in order to do that, the user needs to render a Branch component and pass it the opaque node object returned from the useFocusable() call:
The sole purpose of the Branch component is described in the section above. I'd love to not have this part of the API but, currently, there is no way of providing a React context value to the subtree just from a hook, a Provider element has to be used.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Introduction
I'm in the middle of a rewrite that should get away from the reliance on React context for the focus state updates and use subscriptions to
FocusManager
to propagate the updates surgically only to the components that actually have their focus state changed, thus reducing the amount of unnecessary re-rendering.While working on it, I've changed some user-facing TypeScript types so I would also like to use this opportunity to change the API slightly so it's clearer and more cohesive.
Problem
This RFC seeks feedback for the proposed API and the use-cases that might not work nicely with it.
Core API
FocusManager
FocusManager
is a React-agnostic class that knows how to move focus between the focusable tree nodes in response to the calls to its methods, it maintains the current focus path - path to the focused leaf node in the tree - and can be subscribed to to receive notifications when that path changes.It has to be instantiated by the user and the user needs to decide what events should trigger the navigation methods, it can be anything from the regular key presses to the browser Gamepad API events or even scroll.
<Root>
Root
, (formerlySunbeamProvider
) is the root focusable component. It instantiates the focusable tree and holds its root node as well as passingFocusManager
and some other utilities through the React context to other focusable components in the tree.useFocusable()
A hook that makes the component that uses it a focusable node in the tree.
This is the part of the API that I expect to be used the most. It can be used both for creating a leaf node or a branch node. If the latter is the goal the node has to be passed down the tree through the React context, in order to do that, the user needs to render a
Branch
component and pass it the opaquenode
object returned from theuseFocusable()
call:<Branch>
The sole purpose of the
Branch
component is described in the section above. I'd love to not have this part of the API but, currently, there is no way of providing a React context value to the subtree just from a hook, aProvider
element has to be used.Auxiliary API
TODO
Beta Was this translation helpful? Give feedback.
All reactions