diff options
author | Eric Bailey <git@esb.lol> | 2024-03-05 21:15:42 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-05 21:15:42 -0600 |
commit | 317e0cda7a30d21f35229c096b6ef3284819d19a (patch) | |
tree | 1999f3a766966bda7bcc8934ac0a8b45cc7633cd /src/components/Dialog/context.ts | |
parent | e721f84a2cd64bd98f54049bd17925ddf1b194c8 (diff) | |
download | voidsky-317e0cda7a30d21f35229c096b6ef3284819d19a.tar.zst |
Add `Menu` component (#3097)
* Add POC menu abstraction * Better platform handling * Remove ignore * Add some menu items * Add controlled dropdown * Pass through a11y props * Ignore uninitialized context * Tweaks * Usability improvements * Rename handlers to props * Add radix comment * Ignore known type * Remove todo * Move storybook item * Improve Group matching * Adjust theming
Diffstat (limited to 'src/components/Dialog/context.ts')
-rw-r--r-- | src/components/Dialog/context.ts | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/components/Dialog/context.ts b/src/components/Dialog/context.ts index eb717d8e2..9b571e8e9 100644 --- a/src/components/Dialog/context.ts +++ b/src/components/Dialog/context.ts @@ -21,7 +21,8 @@ export function useDialogControl(): DialogOuterProps['control'] { open: () => {}, close: () => {}, }) - const {activeDialogs} = useDialogStateContext() + const {activeDialogs, openDialogs} = useDialogStateContext() + const isOpen = openDialogs.includes(id) React.useEffect(() => { activeDialogs.current.set(id, control) @@ -31,14 +32,18 @@ export function useDialogControl(): DialogOuterProps['control'] { } }, [id, activeDialogs]) - return { - id, - ref: control, - open: () => { - control.current.open() - }, - close: cb => { - control.current.close(cb) - }, - } + return React.useMemo<DialogOuterProps['control']>( + () => ({ + id, + ref: control, + isOpen, + open: () => { + control.current.open() + }, + close: cb => { + control.current.close(cb) + }, + }), + [id, control, isOpen], + ) } |