All Projects → metonym → svelte-search

metonym / svelte-search

Licence: MIT License
Accessible, customizable Svelte search component

Programming Languages

Svelte
593 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to svelte-search

svelte-multiselect
Keyboard-friendly, accessible and highly customizable multi-select component
Stars: ✭ 91 (+435.29%)
Mutual labels:  input, svelte, svelte-component
svelte-lottie-player
Lottie Player component for Svelte
Stars: ✭ 90 (+429.41%)
Mutual labels:  svelte, svelte-component
PHP-FileUpload
Simple and convenient file uploads — secure by default
Stars: ✭ 53 (+211.76%)
Mutual labels:  input, form
svelte-marquee-text
[CSS GPU Animation] Marquee Text for Svelte
Stars: ✭ 47 (+176.47%)
Mutual labels:  svelte, svelte-component
Voice Overlay Android
🗣 An overlay that gets your user’s voice permission and input as text in a customizable UI
Stars: ✭ 189 (+1011.76%)
Mutual labels:  search, input
Vue Cool Select
Select with autocomplete, slots, bootstrap and material design themes.
Stars: ✭ 195 (+1047.06%)
Mutual labels:  search, input
svelte-inview
A Svelte action that monitors an element enters or leaves the viewport.🔥
Stars: ✭ 358 (+2005.88%)
Mutual labels:  svelte, svelte-component
Ant Plus
🔺 Ant Design 表单简化版
Stars: ✭ 212 (+1147.06%)
Mutual labels:  input, form
svelte-undoable
Memento design pattern in Svelte
Stars: ✭ 39 (+129.41%)
Mutual labels:  svelte, svelte-component
react-file-input-previews-base64
This package provides an easy to use, ready to go and customizable wrapper around file input, with option for image previews and returning file as base64 string.
Stars: ✭ 15 (-11.76%)
Mutual labels:  input, form
dynamic-input-fields-reactjs
Example of the dynamic input fields in ReactJS
Stars: ✭ 31 (+82.35%)
Mutual labels:  input, form
Stf Vue Select
stf vue select - most flexible and customized select
Stars: ✭ 61 (+258.82%)
Mutual labels:  search, input
Voice Overlay Ios
🗣 An overlay that gets your user’s voice permission and input as text in a customizable UI
Stars: ✭ 440 (+2488.24%)
Mutual labels:  search, input
file-input-accessor
Angular directive that provides file input functionality in Angular forms.
Stars: ✭ 32 (+88.24%)
Mutual labels:  input, form
svelte-algolia
Svelte plugin for keeping Algolia indices in sync with custom data fetching functions.
Stars: ✭ 17 (+0%)
Mutual labels:  search, svelte
svelte-multistep-form
Svelte MultiStep Form like, this component is still in beta stage
Stars: ✭ 29 (+70.59%)
Mutual labels:  svelte, form
Vue Formulate
⚡️ The easiest way to build forms with Vue.
Stars: ✭ 1,947 (+11352.94%)
Mutual labels:  input, form
Svelte Tags Input
Svelte tags input is a component to use with Svelte and easily enter tags and customize some options
Stars: ✭ 123 (+623.53%)
Mutual labels:  input, svelte
svelte-intersection-observer
Detect if an element is in the viewport using the Intersection Observer API
Stars: ✭ 151 (+788.24%)
Mutual labels:  svelte, svelte-component
sveld
Generate TypeScript definitions for your Svelte components
Stars: ✭ 281 (+1552.94%)
Mutual labels:  svelte, svelte-component

svelte-search

NPM

Accessible, customizable Svelte search component.

This search component is composed using semantic form and input elements.

See svelte-typeahead for a search component with dropdown results.

Try it in the Svelte REPL.


Installation

Yarn

yarn add -D svelte-search

NPM

npm i -D svelte-search

pnpm

pnpm i -D svelte-search

Styling

This component is unstyled by design. Target the component using the [data-svelte-search] selector.

:global([data-svelte-search] input) {
  width: 100%;
  font-size: 1rem;
  padding: 0.5rem;
  margin: 0.5rem 0;
  border: 1px solid #e0e0e0;
  border-radius: 0.25rem;
}

Usage

Two-way binding

<script>
  import Search from "svelte-search";

  let value = "";
</script>

<Search bind:value />

{#if value}
  <button on:click={() => (value = "")}>Clear "{value}"</button>
{/if}

on:submit

The input element is contained in a form. Use the forwarded submit event to obtain the value when pressing "Enter."

<Search bind:value on:submit={() => console.log("submit", value)} />

Label with placeholder text

$$restProps are forwarded to the input element.

<Search label="My label" placeholder="Placeholder text..." />

Label slot

<Search>
  <span slot="label" style="color: red;">Custom label</span>
</Search>

Visually hidden label

Set hideLabel to true to visually hide the label.

<Search hideLabel label="My label" placeholder="Placeholder text..." />

Focus (declarative)

Use the autofocus prop to declaratively focus the input.

<Search autofocus />

Focus (programmatic)

Bind the ref prop to programmatically focus the input.

<script>
  import Search from "svelte-search";

  let ref = null;
</script>

<Search bind:ref />

<button on:click={() => ref.focus()}>Focus</button>

Debounced input

Use the debounce prop to specify the debounce value in milliseconds.

<script>
  import Search from "svelte-search";

  let events = [];
</script>

<Search
  debounce={800}
  on:type={({ detail: value }) => (events = [...events, value])}
/>

<pre>
  {JSON.stringify(events, null, 2)}
</pre>

API

$$restProps are forwarded to the input element.

Props

Prop name Type Default value
value string ""
label string "Search"
hideLabel boolean false
debounce number 0
ref HTMLInputElement null
id string "search" + Math.random().toString(36)
removeFormAriaAttributes boolean false
autofocus boolean false

Forwarded events

  • on:input
  • on:change
  • on:submit
  • on:focus
  • on:blur
  • on:keydown

Dispatched events

  • on:type: fired when the the input value is updated
  • on:clear: fired when clicking the "X" button to clear the input value
<Search
  on:type={(e) => {
    console.log("type", e.detail); // input value
  }}
  on:clear={() => {
    console.log("clear");
  }}
/>

TypeScript

Svelte version 3.31 or greater is required to use this component with TypeScript.

TypeScript definitions are located in the types folder.

Changelog

Changelog

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].