diff --git a/src/components/navigation/navigation-disclosure.tsx b/src/components/navigation/navigation-disclosure.tsx index 5a6dda32..4bfffdba 100644 --- a/src/components/navigation/navigation-disclosure.tsx +++ b/src/components/navigation/navigation-disclosure.tsx @@ -16,15 +16,33 @@ const NavigationDisclosureButton = ({ children, LeftIcon }: NavigationDisclosure ); }; +interface CloseFunction { + (focusableElement?: HTMLElement | React.MutableRefObject): void; +} + +interface ChildrenType { + (props: { close: CloseFunction }): React.ReactNode; +} + export interface NavigationDisclosureProps { - children: React.ReactNode; + children: ChildrenType | React.ReactNode; defaultOpen?: boolean; } +const renderDisclosureChildren = ({ + children, + close, +}: { + children: ChildrenType | React.ReactNode; + close: CloseFunction; +}) => { + return typeof children === "function" ? children({ close }) : children; +}; + const NavigationDisclosure = ({ children, defaultOpen }: NavigationDisclosureProps) => { return ( - {children} + {({ close }) => <>{renderDisclosureChildren({ children, close })}} ); };