@@ -2,8 +2,7 @@ import { CheckIcon, ChevronsUpDownIcon, Link2Icon, Link2OffIcon } from "lucide-r
22import { useParams } from "next/navigation" ;
33import { useQueryState } from "nuqs" ;
44import { Hex } from "viem" ;
5- import { useState } from "react" ;
6- import { useEffect } from "react" ;
5+ import { useEffect , useLayoutEffect , useState } from "react" ;
76import { Table } from "@latticexyz/config" ;
87import { Button } from "../../../../../../components/ui/Button" ;
98import {
@@ -36,6 +35,7 @@ export function TableSelector({ tables }: { tables?: Table[] }) {
3635 const { id : chainId } = useChain ( ) ;
3736 const [ selectedTableId , setTableId ] = useQueryState ( "tableId" ) ;
3837 const [ open , setOpen ] = useState ( false ) ;
38+ const [ searchValue , setSearchValue ] = useState ( "" ) ;
3939 const selectedTableConfig = tables ?. find ( ( { tableId } ) => tableId === selectedTableId ) ;
4040
4141 useEffect ( ( ) => {
@@ -44,6 +44,16 @@ export function TableSelector({ tables }: { tables?: Table[] }) {
4444 }
4545 } , [ selectedTableId , setTableId , tables ] ) ;
4646
47+ useLayoutEffect ( ( ) => {
48+ if ( open && selectedTableId && selectedTableConfig ) {
49+ setTimeout ( ( ) => {
50+ const selectedTableId = constructTableName ( selectedTableConfig , worldAddress as Hex , chainId ) ;
51+ const selectedElement = document . querySelector ( `[data-value="${ selectedTableId } "]` ) ;
52+ selectedElement ?. scrollIntoView ( { behavior : "instant" , block : "center" } ) ;
53+ } , 0 ) ;
54+ }
55+ } , [ chainId , open , selectedTableConfig , selectedTableId , worldAddress ] ) ;
56+
4757 return (
4858 < div className = "w-full" >
4959 < Popover open = { open } onOpenChange = { setOpen } >
@@ -68,9 +78,16 @@ export function TableSelector({ tables }: { tables?: Table[] }) {
6878
6979 < PopoverContent className = "w-[--radix-popover-trigger-width] p-0" >
7080 < Command >
71- < CommandInput placeholder = "Search tables..." className = "font-mono" />
81+ < CommandInput
82+ placeholder = "Search tables..."
83+ className = "font-mono"
84+ value = { searchValue }
85+ onValueChange = { setSearchValue }
86+ />
7287 < CommandList >
73- < CommandEmpty className = "py-4 text-center font-mono text-sm" > No table found.</ CommandEmpty >
88+ < CommandEmpty className = "py-4 text-center font-mono text-sm text-muted-foreground" >
89+ No table found.
90+ </ CommandEmpty >
7491 < CommandGroup >
7592 { tables ?. map ( ( table ) => {
7693 return (
0 commit comments