Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
final fixes
  • Loading branch information
mnajdova committed Dec 18, 2024
commit 823db7cbd1af869b9c6bbc08b7a27de7d7158da2
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ describe('<AlertDialog.Popup />', () => {
</Dialog.Portal>
</Dialog.Root>,
);

const parentDialog = screen.getByTestId('parent-dialog');
const nestedDialog = screen.getByTestId('nested-dialog');

expect(parentDialog).not.to.have.attribute('data-nested');
expect(nestedDialog).to.have.attribute('data-nested');

expect(parentDialog).to.have.attribute('data-has-nested-dialogs');
expect(nestedDialog).not.to.have.attribute('data-has-nested-dialogs');
});
Expand Down
11 changes: 5 additions & 6 deletions packages/react/src/dialog/root/DialogRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ const DialogRoot = function DialogRoot(props: DialogRoot.Props) {

const nested = Boolean(parentDialogRootContext);

const contextValue = React.useMemo(
() => ({ ...dialogRoot, nested, dismissible }),
[dialogRoot, nested, dismissible],
);
const dialogContextValue = React.useMemo(() => ({ ...dialogRoot, nested }), [dialogRoot, nested]);

const dialogRootContextValue = React.useMemo(() => ({ dismissible }), [dismissible]);

return (
<DialogContext.Provider value={contextValue}>
<DialogRootContext.Provider value={contextValue}>
<DialogContext.Provider value={dialogContextValue}>
<DialogRootContext.Provider value={dialogRootContextValue}>
<PortalContext.Provider value={dialogRoot.mounted}>{children}</PortalContext.Provider>
</DialogRootContext.Provider>
</DialogContext.Provider>
Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/dialog/root/DialogRootContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as React from 'react';
import { DialogContext } from '../utils/DialogContext';

export interface DialogRootContext extends DialogContext {
export interface DialogRootContext {
/**
* Determines whether the dialog should close on outside clicks.
*/
Expand All @@ -19,6 +19,10 @@ export function useOptionalDialogRootContext() {
const dialogRootContext = React.useContext(DialogRootContext);
const dialogContext = React.useContext(DialogContext);

if (dialogContext === undefined && dialogRootContext === undefined) {
return undefined;
}

return {
...dialogRootContext,
...dialogContext,
Expand Down