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
Currently, SelectMenu manages its own open/closed state. By calling setOpen from SelectMenu.Context, a component descendent of SelectMenu can open or close the menu. But it’s currently difficult for a component outsideSelectMenu’s render tree to open or close it.
In another project at GitHub using PRC, there is a need to be able to open SelectMenu components from places outside of the SelectMenu hierarchy.
Solution
SelectMenu should accept an open prop, which controls whether the menu is open/visible or closed/hidden.
Alternatives
Another project at GitHub using PRC is able to auto-open the SelectMenu s by defining a custom SelectMenu component which renders a SelectMenuInternal component which consumes a useSelectMenuInternal hook.
Because useSelectMenuInternal is called by SelectMenuInternal (a child of SelectMenu), it has access to both SelectMenu.Context and a set of propagated props (specifically, open, onOpen and onClose).
By using useEffect to respond to changes in SelectMenu.Context and props, useSelectMenuInternal is able to synchronize the SelectMenu.Context’s internal open value with the value of the open prop.
This effectively allows the SelectMenu component to be controlled.
The text was updated successfully, but these errors were encountered:
(Moved over from the ds repo thanks @smockle !)
Problem
Currently,
SelectMenu
manages its own open/closed state. By callingsetOpen
fromSelectMenu.Context
, a component descendent ofSelectMenu
can open or close the menu. But it’s currently difficult for a component outsideSelectMenu
’s render tree to open or close it.In another project at GitHub using PRC, there is a need to be able to open
SelectMenu
components from places outside of the SelectMenu hierarchy.Solution
SelectMenu
should accept anopen
prop, which controls whether the menu is open/visible or closed/hidden.Alternatives
Another project at GitHub using PRC is able to auto-open the
SelectMenu
s by defining a customSelectMenu
component which renders aSelectMenuInternal
component which consumes auseSelectMenuInternal
hook.Because
useSelectMenuInternal
is called bySelectMenuInternal
(a child ofSelectMenu
), it has access to bothSelectMenu.Context
and a set of propagated props (specifically,open
,onOpen
andonClose
).By using
useEffect
to respond to changes inSelectMenu.Context
and props,useSelectMenuInternal
is able to synchronize theSelectMenu.Context
’s internalopen
value with the value of theopen
prop.This effectively allows the
SelectMenu
component to be controlled.The text was updated successfully, but these errors were encountered: