11import * as React from "react"
2+
3+ import { cn } from "@/lib/utils"
4+
5+ import { useRooPortal } from "./hooks/useRooPortal"
26import {
37 DropdownMenu ,
48 DropdownMenuContent ,
59 DropdownMenuItem ,
610 DropdownMenuTrigger ,
711 DropdownMenuSeparator ,
812} from "./dropdown-menu"
9- import { cn } from "@/lib/utils"
1013
11- // Constants for option types
1214export enum DropdownOptionType {
1315 ITEM = "item" ,
1416 SEPARATOR = "separator" ,
@@ -19,7 +21,7 @@ export interface DropdownOption {
1921 value : string
2022 label : string
2123 disabled ?: boolean
22- type ?: DropdownOptionType // Optional type to specify special behaviors
24+ type ?: DropdownOptionType
2325}
2426
2527export interface SelectDropdownProps {
@@ -38,8 +40,6 @@ export interface SelectDropdownProps {
3840 shortcutText ?: string
3941}
4042
41- // TODO: Get rid of this and use the native @shadcn /ui `Select` component.
42-
4343export const SelectDropdown = React . forwardRef < React . ElementRef < typeof DropdownMenuTrigger > , SelectDropdownProps > (
4444 (
4545 {
@@ -59,24 +59,19 @@ export const SelectDropdown = React.forwardRef<React.ElementRef<typeof DropdownM
5959 } ,
6060 ref ,
6161 ) => {
62- // Track open state
6362 const [ open , setOpen ] = React . useState ( false )
63+ const portalContainer = useRooPortal ( "roo-portal" )
6464
65- // Find the selected option label
6665 const selectedOption = options . find ( ( option ) => option . value === value )
6766 const displayText = selectedOption ?. label || placeholder || ""
6867
69- // Handle menu item click
7068 const handleSelect = ( option : DropdownOption ) => {
71- // Check if this is an action option by its explicit type
7269 if ( option . type === DropdownOptionType . ACTION ) {
73- window . postMessage ( {
74- type : "action" ,
75- action : option . value ,
76- } )
70+ window . postMessage ( { type : "action" , action : option . value } )
7771 setOpen ( false )
7872 return
7973 }
74+
8075 onChange ( option . value )
8176 setOpen ( false )
8277 }
@@ -94,7 +89,7 @@ export const SelectDropdown = React.forwardRef<React.ElementRef<typeof DropdownM
9489 triggerClassName ,
9590 ) }
9691 style = { {
97- width : "100%" , // Take full width of parent
92+ width : "100%" , // Take full width of parent.
9893 minWidth : "0" ,
9994 maxWidth : "100%" ,
10095 } } >
@@ -121,17 +116,16 @@ export const SelectDropdown = React.forwardRef<React.ElementRef<typeof DropdownM
121116 sideOffset = { sideOffset }
122117 onEscapeKeyDown = { ( ) => setOpen ( false ) }
123118 onInteractOutside = { ( ) => setOpen ( false ) }
119+ container = { portalContainer }
124120 className = { cn (
125121 "bg-vscode-dropdown-background text-vscode-dropdown-foreground border border-vscode-dropdown-border z-50" ,
126122 contentClassName ,
127123 ) } >
128124 { options . map ( ( option , index ) => {
129- // Handle separator type
130125 if ( option . type === DropdownOptionType . SEPARATOR ) {
131126 return < DropdownMenuSeparator key = { `sep-${ index } ` } />
132127 }
133128
134- // Handle shortcut text type (disabled label for keyboard shortcuts)
135129 if (
136130 option . type === DropdownOptionType . SHORTCUT ||
137131 ( option . disabled && shortcutText && option . label . includes ( shortcutText ) )
@@ -143,7 +137,6 @@ export const SelectDropdown = React.forwardRef<React.ElementRef<typeof DropdownM
143137 )
144138 }
145139
146- // Regular menu items
147140 return (
148141 < DropdownMenuItem
149142 key = { `item-${ option . value } ` }
0 commit comments