diff --git a/cmdk/src/index.tsx b/cmdk/src/index.tsx index fcbd83c..35f56b6 100644 --- a/cmdk/src/index.tsx +++ b/cmdk/src/index.tsx @@ -5,24 +5,29 @@ import { commandScore } from './command-score' type Children = { children?: React.ReactNode } type DivProps = React.HTMLAttributes -type LoadingProps = Children & DivProps & { - /** Estimated progress of loading asynchronous options. */ - progress?: number -} +type LoadingProps = Children & + DivProps & { + /** Estimated progress of loading asynchronous options. */ + progress?: number + } type EmptyProps = Children & DivProps & {} type SeparatorProps = DivProps & { /** Whether this separator should always be rendered. Useful if you disable automatic filtering. */ alwaysRender?: boolean } -type DialogProps = RadixDialog.DialogProps & - CommandProps & { - /** Provide a className to the Dialog overlay. */ - overlayClassName?: string - /** Provide a className to the Dialog content. */ - contentClassName?: string - /** Provide a custom element the Dialog should portal into. */ - container?: HTMLElement - } +type CommonDialogProps = { + /** Provide a className to the Dialog overlay. */ + overlayClassName?: string + /** Provide a className to the Dialog content. */ + contentClassName?: string + /** Provide a custom element the Dialog should portal into. */ + container?: HTMLElement +} +type DialogProps = RadixDialog.DialogProps & CommandProps & CommonDialogProps +type DialogPortalWrapperProps = RadixDialog.DialogPortalProps & CommandProps & CommonDialogProps +type DialogPortalProps = { + ref: React.ForwardedRef +} & (DialogProps | DialogPortalWrapperProps) type ListProps = Children & DivProps & {} type ItemProps = Children & Omit & { @@ -799,6 +804,17 @@ const List = React.forwardRef((props, forwardedRef) = ) }) +const DialogPortal = ({ overlayClassName, contentClassName, container, label, ref, ...etc }: DialogPortalProps) => { + return ( + + + + + + + ) +} + /** * Renders the command menu in a Radix Dialog. */ @@ -806,16 +822,19 @@ const Dialog = React.forwardRef((props, forwardedRe const { open, onOpenChange, overlayClassName, contentClassName, container, ...etc } = props return ( - - - - - - + ) }) +/** + * Renders the command menu in a Radix Dialog without the root element + */ +const DialogPortalWrapper = React.forwardRef((props, forwardedRef) => { + const { overlayClassName, contentClassName, container, ...etc } = props + return +}) + /** * Automatically renders when there are no results for the search query. */ @@ -860,6 +879,7 @@ const pkg = Object.assign(Command, { Group, Separator, Dialog, + DialogPortal: DialogPortalWrapper, Empty, Loading, })