Trading

Instrument Search

Virtualized search box for picking a trading instrument across exchanges. Supports multi-word matching against symbol, name, exchange, and type, plus full keyboard navigation.

Preview

Fullscreen

Source

Copy this file to components/trading/instrument-search.tsx

tsx
'use client'

import * as React from 'react'
import { useState, useMemo, useEffect, useRef } from 'react'
import { useVirtualizer } from '@tanstack/react-virtual'
import { Search, X } from 'lucide-react'
import { cn } from '@/lib/utils'

export interface Instrument {
  symbol: string
  name?: string
  exchange?: string
  type?: string
}

export interface InstrumentSearchProps {
  value?: Instrument | null
  onSelect: (instrument: Instrument | null) => void
  instruments: Instrument[]
  placeholder?: string
  className?: string
}

// Virtualized instrument search with multi-word matching and keyboard navigation.
// See components/trading/instrument-search.tsx for the full implementation.

Props

PropType
instruments*Instrument[]
onSelect*(instrument: Instrument | null) => void
valueInstrument | null
placeholderstring
classNamestring