({
children,
id,
...props
}: React.ComponentProps<typeof DropdownMenuSub> & {
id?: string;
})
| 688 | let submenuIdCounter = 0; |
| 689 | |
| 690 | function DropDrawerSub({ |
| 691 | children, |
| 692 | id, |
| 693 | ...props |
| 694 | }: React.ComponentProps<typeof DropdownMenuSub> & { |
| 695 | id?: string; |
| 696 | }) { |
| 697 | const { isMobile } = useDropDrawerContext(); |
| 698 | const { registerSubmenuContent } = React.useContext(SubmenuContext); |
| 699 | |
| 700 | // Generate a simple numeric ID instead of using React.useId() |
| 701 | const [generatedId] = React.useState(() => `submenu-${submenuIdCounter++}`); |
| 702 | const submenuId = id || generatedId; |
| 703 | |
| 704 | // Extract submenu content to register with parent |
| 705 | React.useEffect(() => { |
| 706 | if (!registerSubmenuContent) return; |
| 707 | |
| 708 | // Find the SubContent within this Sub |
| 709 | const contentItems: React.ReactNode[] = []; |
| 710 | React.Children.forEach(children, (child) => { |
| 711 | if (React.isValidElement(child) && child.type === DropDrawerSubContent) { |
| 712 | // Add all children of the SubContent to the result |
| 713 | React.Children.forEach( |
| 714 | (child.props as { children?: React.ReactNode }).children, |
| 715 | (contentChild) => { |
| 716 | contentItems.push(contentChild); |
| 717 | }, |
| 718 | ); |
| 719 | } |
| 720 | }); |
| 721 | |
| 722 | // Register the content with the parent |
| 723 | if (contentItems.length > 0) { |
| 724 | registerSubmenuContent(submenuId, contentItems); |
| 725 | } |
| 726 | }, [children, registerSubmenuContent, submenuId]); |
| 727 | |
| 728 | if (isMobile) { |
| 729 | // For mobile, we'll use the context to manage submenu state |
| 730 | // Process children to pass the submenu ID to the trigger and content |
| 731 | const processedChildren = React.Children.map(children, (child) => { |
| 732 | if (!React.isValidElement(child)) return child; |
| 733 | |
| 734 | if (child.type === DropDrawerSubTrigger) { |
| 735 | return React.cloneElement( |
| 736 | child as React.ReactElement, |
| 737 | { |
| 738 | ...(child.props as object), |
| 739 | "data-parent-submenu-id": submenuId, |
| 740 | "data-submenu-id": submenuId, |
| 741 | // Use only data attributes, not custom props |
| 742 | "data-parent-submenu": submenuId, |
| 743 | } as React.HTMLAttributes<HTMLElement>, |
| 744 | ); |
| 745 | } |
| 746 | |
| 747 | if (child.type === DropDrawerSubContent) { |
nothing calls this directly
no test coverage detected