TanStack Select

repository·main·Indexed 42 days ago

https://github.com/tanstack/select

A headless UI library for building advanced, highly customizable select, autocomplete, and dropdown components. It provides logic, state management, and accessibility features without prescribing styling or DOM structure. Available as a core package (@tanstack/select) for vanilla JavaScript, with dedicated adapters for React (@tanstack/react-select) and Solid (@tanstack/solid-select).

Tokens
1.3K
Snippets
11
Records
12
Agent score
55%

What's inside TanStack Select

  1. What is TanStack Select

    main
    TanStack Select is a headless UI library designed for building advanced, highly customizable select, autocomplete, and dropdown components. Because it is headless, it provides the logic, state management, and accessibility features without prescribing any specific styling or DOM structure, allowing you to build components that match your application's design system perfectly.
  2. Install TanStack Select

    main

    Install the package corresponding to your framework. Use @tanstack/react-select for React applications, or @tanstack/select for vanilla JavaScript implementations.

    # For React
    npm install @tanstack/react-select
    
    # For Vanilla JS
    npm install @tanstack/select
    # Npm
    npm install @tanstack/react-select
    npm install @tanstack/select # no framework, just vanilla js
  3. Install TanStack Select Core for Vanilla JS or other frameworks

    main

    To use TanStack Select in a Vanilla JS environment or with a framework not explicitly supported by a dedicated package, install the core @tanstack/select package. Note that the framework-specific packages (@tanstack/react-select and @tanstack/solid-select) also re-export everything from this core package.

    npm install @tanstack/select
  4. Use TanStack Select with SolidJS

    main

    The @tanstack/solid-select package provides the SolidJS implementation of TanStack Select. It re-exports all core logic from @tanstack/select, allowing you to use the headless selection logic within SolidJS applications.

    To use the library, import the hooks or components directly from @tanstack/solid-select. Note that hooks should be imported individually rather than through barrel files to ensure optimal tree-shaking and compatibility with Solid's reactivity system.

    import { useSelect } from '@tanstack/solid-select'
    
    // Use the hook within a Solid component
    const MyComponent = () => {
      const select = useSelect({ 
        // options from @tanstack/select
      })
      
      return (
        // Your Solid implementation
      )
    }
  5. Use TanStack Select with React

    main

    The @tanstack/react-select package provides the React implementation of TanStack Select. It re-exports all core functionality from @tanstack/select, allowing you to use the headless select logic within React components.

    Note on Imports: To ensure optimal tree-shaking and avoid issues with barrel files, it is recommended to import hooks individually rather than from a single entry point if the package structure allows.

    import { useSelect } from '@tanstack/react-select';
    
    // Use the hook within your React component
    function MyComponent() {
      const select = useSelect({
        // options from @tanstack/select
      });
    
      return <div>{/* Render your select UI using select state */}</div>;
    }
  6. The `select` constant

    main

    The @tanstack/select package exports a constant select with the string value 'select'. This is likely used as a type identifier or a key within the TanStack ecosystem to distinguish select-related logic or state.

    import { select } from '@tanstack/select'
    
    console.log(select) // 'select'