Skip to content

Commit

Permalink
adjust children type for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sirineJ committed Dec 5, 2024
1 parent 517ee80 commit 6b2ccd8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/circuit-ui/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface DialogProps
/**
* a function that returns the content of the dialog.
*/
children?: () => ReactNode;
children?: ({ onClose }: { onClose?: DialogProps['onClose'] }) => ReactNode;
/**
* Text label for the close button for screen readers.
* Important for accessibility.
Expand Down Expand Up @@ -255,7 +255,9 @@ export const Dialog = forwardRef<HTMLDialogElement, DialogProps>(
<CloseButton onClick={handleDialogClose} className={classes.close}>
{closeButtonLabel}
</CloseButton>
{open && <div className={classes.content}>{children?.()}</div>}
{open && (
<div className={classes.content}>{children?.({ onClose })}</div>
)}
</dialog>
</>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/circuit-ui/components/Dialog/ModalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import {
useState,
} from 'react';

import type { Optional } from '../../types/util.js';

import type { DialogProps } from './Dialog.js';
import type { ModalDialogComponent } from './createUseModalDialog.js';

type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
export type SetModalArgs = Optional<DialogProps, 'open'>;

// keep initial state compatible with the old version of this component
Expand Down

0 comments on commit 6b2ccd8

Please sign in to comment.