@@ -53,6 +53,7 @@ function FolderTree(treeProps: TreeProps) {
5353 const [ dialogContent , setDialogContent ] = useState < React . ReactNode > ( null ) ;
5454 const dialogRef = useRef < HTMLDialogElement > ( null ) ;
5555 const [ hasSubscribed , setHasSubscribed ] = useState < boolean > ( false ) ;
56+ const [ isTreeLoaded , setIsTreeLoaded ] = useState ( false ) ;
5657
5758 useEffect ( ( ) => {
5859 // If treeData is passed as a prop, build the tree
@@ -115,6 +116,23 @@ function FolderTree(treeProps: TreeProps) {
115116 }
116117 } , [ isConnected ] ) ;
117118
119+ /**
120+ * Auto select and open the root node when the tree data is loaded
121+ */
122+ useEffect ( ( ) => {
123+ if ( treeData && treeData . length > 0 && ! isTreeLoaded && treeRef . current ) {
124+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
125+ // @ts -ignore
126+ treeRef . current . select ( treeData [ 0 ] . id ) ;
127+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
128+ // @ts -ignore
129+ treeRef . current . open ( treeData [ 0 ] . id ) ;
130+ setIsTreeLoaded ( true ) ;
131+ } else if ( ! treeData ) {
132+ setIsTreeLoaded ( false ) ;
133+ }
134+ } , [ treeData , isTreeLoaded ] ) ;
135+
118136 /**
119137 * toggleDialog - toggle the dialog open/close state
120138 */
@@ -586,7 +604,7 @@ function FolderTree(treeProps: TreeProps) {
586604 }
587605
588606 return (
589- < div className = "flex flex-col gap-1" >
607+ < div className = "flex flex-col gap-1 h-full " >
590608 { treeProps . isHeader && (
591609 < div className = 'flex flex-col items-center p-1 gap-1 bg-mountain-mist-100 dark:bg-mountain-mist-950' >
592610 < Login onSuccess = { onGoogleLoginSuccess } logoutCallback = { onGoogleLogout } />
@@ -599,7 +617,7 @@ function FolderTree(treeProps: TreeProps) {
599617 storageCapacity = { capacity }
600618 />
601619 ) }
602- < div ref = { ref } style = { { height : treeProps . treeData ? '40vh' : '100vh' } } >
620+ < div ref = { ref } className = "flex-1 min-h-0" >
603621 < Tree
604622 ref = { treeRef }
605623 className = "text-md border border-shark-200 bg-mountain-mist-100 text-shark-900 dark:border-shark-950 dark:bg-mountain-mist-950 dark:text-shark-200"
0 commit comments