Skip to main content

Token Selector

A dropdown component that allows users to search and select tokens from a list.

import { TokenSelector, type Token } from "@/components/ui/token-selector"

const userTokens: Token[] = [
{ symbol: "ETH", name: "Ethereum", icon: "/img/eth.png", balance: "70.124" },
{ symbol: "BTC", name: "Bitcoin", icon: "/img/btc.png", balance: "2.451" },
]

const popularTokens: Token[] = [
{ symbol: "STX", name: "Stacks", icon: "/img/stx-logo.png" },
{ symbol: "DAI", name: "Dai", icon: "/img/dai.png" },
]

const quickTokens: Token[] = [
{ symbol: "ETH", name: "Ethereum", icon: "/img/eth.png" },
{ symbol: "BTC", name: "Bitcoin", icon: "/img/btc.png" },
{ symbol: "STX", name: "Stacks", icon: "/img/stx-logo.png" },
{ symbol: "DAI", name: "Dai", icon: "/img/dai.png" },
]

function MyComponent() {
const [selected, setSelected] = React.useState<Token>()

return (
<TokenSelector
tokens={userTokens}
popularTokens={popularTokens}
quickSelectTokens={quickTokens}
value={selected}
onSelect={setSelected}
/>
)
}

API Reference

Token

The token data shape used throughout the component.

PropertyTypeRequiredDescription
symbolstringYesToken ticker symbol (e.g. "ETH")
namestringYesFull token name (e.g. "Ethereum")
iconstringYesPath to the token icon image
balancestringNoUser's balance of this token

TokenSelector

PropTypeDefaultDescription
tokensToken[]Tokens the user holds (shown under "Your Tokens")
popularTokensToken[][]Popular tokens (shown under "Popular Tokens")
quickSelectTokensToken[][]Tokens shown as quick-select pills at the top
valueTokenCurrently selected token
onSelect(token: Token) => voidCallback when a token is selected
triggerReactNodeCustom trigger element (defaults to built-in button)
placeholderstring"Search categories"Search input placeholder text

Accessibility

  • Built on top of the Dialog primitive with full focus trapping
  • Search input is auto-focused for keyboard navigation
  • Escape key closes the selector
  • Token list items are keyboard-navigable buttons