Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/snehalbaghel/select-kit

A one-stop solution for all your select/combobox/autocomplete needs for Svelte
https://github.com/snehalbaghel/select-kit

cmdk combobox command-menu select svelte sveltejs

Last synced: 25 days ago
JSON representation

A one-stop solution for all your select/combobox/autocomplete needs for Svelte

Awesome Lists containing this project

README

        

# Select Kit

This library is a one-stop solution for building WAI-ARIA compliant navigation/command/select menus. The components provided are headless so they can be styled as per your requirement, they are also [composable](https://github.com/pacocoursey/cmdk/blob/main/ARCHITECTURE.md) in nature so its easy to use. Refer the various examples below to implement the variation you want to build.



## Installation

```bash
npm install svelte-select-kit
```

## Basic Structure of a Combobox

- `Select.Root`: The root component which sets up label, context and the store:
- `Select.Input`: Combobox's input, keeps track of query
- `Select.Select`: Use this if you're building a select only component
- `Select.ListBox`: Root component of the items
- `Select.Item`: A single selectable item, you will have multiple of these
- `Select.Separator`: Just a div with role='separator'
- `Select.NoResults`: Rendered when there are no results found
- `Select.Button`: A button to toggle the list-box

## Stable Release TODOS:

- [ ] Multiselect Support
- [ ] Type Ahead Support for 'Select Only' combobox
- [ ] Some API improvements

## Examples

For full examples refer the [examples](/src/examples) folder in this repo

> **NOTE:** We use [@smui/common](https://www.npmjs.com/package/@smui/common) to forward events of our components, it works similarly to the the Svelte syntax apart from one important difference: for adding event modifiers the `|` should be replaced by `$` i.e. `on:click|preventDefault` becomes `on:click$preventDefault`. For information on this refer this [issue](https://github.com/sveltejs/svelte/issues/2837).

### Basic Example

```svelte

import Select from 'svelte-select-kit';



{#if open}
No results found
console.log('clicked one')} id="one">One
console.log('clicked two')} id="two">Two
console.log('clicked three')} id="three">Three
console.log('clicked four')} id="four">Four
{/if}

```

### Disable Filtering

ListBox supports shouldFilter prop which will disable filtering, to access the input value to perform your own filtering you may bind to the input component's value prop.

```svelte

import Select from 'svelte-select-kit';

let value = '';
// Add your logic here for filtering..


...

...
```

### With Chevron Button

```svelte

import Select from '$lib/index.js';


{open ? '⌃' : '⌄'}

{#if open}
No results found
console.log('clicked one')} id="one">One
console.log('clicked two')} id="two">Two
console.log('clicked three')} id="three">Three
console.log('clicked four')} id="four">Four
{/if}

```