svelte-typeahead 2.4.1 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,36 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.2.0](https://github.com/metonym/svelte-typeahead/releases/tag/v4.2.0) - 2021-10-26
9
+
10
+ **Features**
11
+
12
+ - use TypeScript generics so that the item type can be inferred from `data` value
13
+
14
+ ## [4.1.0](https://github.com/metonym/svelte-typeahead/releases/tag/v4.1.0) - 2021-10-03
15
+
16
+ **Features**
17
+
18
+ - render a "no-results" slot when the search value does not yield results
19
+ - add `value` to the default slot props
20
+
21
+ ## [4.0.0](https://github.com/metonym/svelte-typeahead/releases/tag/v4.0.0) - 2021-09-05
22
+
23
+ **Breaking Changes**
24
+
25
+ - use `.svelte.d.ts` extension for component TypeScript definition
26
+
27
+ ## [3.0.0](https://github.com/metonym/svelte-typeahead/releases/tag/v3.0.0) - 2021-03-16
28
+
29
+ **Breaking Changes**
30
+
31
+ - the `ul` element is rendered even without results to preserve the accessibility label
32
+
33
+ **Fixes**
34
+
35
+ - disable form ARIA attributes in `svelte-search`
36
+ - pass the correct `aria-activedescendant` item to `svelte-search`
37
+
8
38
  ## [2.4.1](https://github.com/metonym/svelte-typeahead/releases/tag/v2.4.1) - 2021-03-14
9
39
 
10
40
  **Fixes**
package/README.md CHANGED
@@ -8,23 +8,47 @@
8
8
 
9
9
  This component uses the lightweight [fuzzy](https://github.com/mattyork/fuzzy) library for client-side, fuzzy search and follows [WAI-ARIA guidelines](https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html).
10
10
 
11
- Try it in the [Svelte REPL](https://svelte.dev/repl/a1b828d80de24f7e995b2365782c8d04?version=3.24.1).
11
+ Try it in the [Svelte REPL](https://svelte.dev/repl/a1b828d80de24f7e995b2365782c8d04).
12
12
 
13
13
  ---
14
14
 
15
15
  <!-- TOC -->
16
16
 
17
- ## Install
17
+ ## Installation
18
+
19
+ **Yarn**
18
20
 
19
21
  ```bash
20
22
  yarn add -D svelte-typeahead
21
- # OR
23
+ ```
24
+
25
+ **NPM**
26
+
27
+ ```bash
22
28
  npm i -D svelte-typeahead
23
29
  ```
24
30
 
25
31
  ## Usage
26
32
 
27
- [svelte-search](https://github.com/metonym/svelte-search) is used as the underlying search input component. `$$restProps` are forwarded to `svelte-search`.
33
+ ### SvelteKit set-up
34
+
35
+ To use this component with [SvelteKit](https://github.com/sveltejs/kit) or vite-powered set-ups, instruct `vite` to optimize `"fuzzy"` in your configuration.
36
+
37
+ ```js
38
+ // svelte.config.js
39
+ const config = {
40
+ kit: {
41
+ target: "#svelte",
42
+ vite: {
43
+ optimizeDeps: {
44
+ include: ["fuzzy"],
45
+ },
46
+ },
47
+ },
48
+ };
49
+
50
+ export default config;
51
+ ```
28
52
 
29
53
  ### Styling
30
54
 
@@ -78,6 +102,18 @@ Use a slot to render custom results.
78
102
  </Typeahead>
79
103
  ```
80
104
 
105
+ ### No results
106
+
107
+ Use the "no-results" slot to render a message if the search value does not yield results.
108
+
109
+ ```svelte
110
+ <Typeahead {data} {extract} let:value>
111
+ <svelte:fragment slot="no-results">
112
+ No results found for "{value}"
113
+ </svelte:fragment>
114
+ </Typeahead>
115
+ ```
116
+
81
117
  ### Limit the number of results
82
118
 
83
119
  Use the `limit` prop to specify the maximum number of results to display. The default limit is `Infinity`.
@@ -94,6 +130,8 @@ Example for disabling and filtering items by their title length:
94
130
 
95
131
  ```svelte
96
132
  <script>
133
+ import Typeahead from "svelte-typeahead";
134
+
97
135
  const disable = (item) => item.state.length > 4;
98
136
  const filter = (item) => item.state.length > 8;
99
137
  </script>
@@ -104,18 +142,13 @@ Example for disabling and filtering items by their title length:
104
142
  Example for disabling items after selecting them:
105
143
 
106
144
  ```svelte
107
- <script>
108
- function handleSelect(e) {
109
- let i = e.detail.originalIndex;
110
- data[i].selected = true;
111
- }
112
- </script>
113
-
114
145
  <Typeahead
115
146
  {data}
116
147
  extract={(item) => item.state}
117
148
  disable={(item) => item.selected}
118
- on:select={handleSelect}
149
+ on:select={({ detail }) => {
150
+ data[detail.originalIndex].selected = true;
151
+ }}
119
152
  />
120
153
  ```
121
154
 
@@ -152,31 +185,23 @@ Set `focusAfterSelect` to `true` to re-focus the search input after selecting a
152
185
 
153
186
  ```svelte
154
187
  <script>
188
+ import Typeahead from "svelte-typeahead";
189
+
155
190
  let events = [];
156
191
 
157
- function update(event, detail) {
158
- events = [...events, JSON.stringify({ event, detail }, null, 2)];
159
- }
192
+ const update = (event, detail) => (events = [...events, { event, detail }]);
160
193
  </script>
161
194
 
162
195
  <Typeahead
163
196
  {data}
164
197
  {extract}
165
- on:select={(e) => {
166
- update("select", e.detail);
167
- }}
168
- on:clear={() => {
169
- update("clear");
170
- }}
198
+ on:select={(e) => update("select", e.detail)}
199
+ on:clear={() => update("clear")}
171
200
  />
172
201
 
173
- <ul>
174
- {#each events as event}
175
- <li>
176
- <pre>{event}</pre>
177
- </li>
178
- {/each}
179
- </ul>
202
+ {#each events as event}
203
+ <pre>{JSON.stringify(event, null, 2)}</pre>
204
+ {/each}
180
205
  ```
181
206
 
182
207
  ### Forwarded events
@@ -191,22 +216,11 @@ The following events are forwarded to the [svelte-search](https://github.com/met
191
216
  - on:blur
192
217
  - on:keydown
193
218
 
194
- ## Usage with svite
195
-
196
- To use this component with [svite](https://github.com/dominikg/svite), add the following to your `vite.config.js`:
197
-
198
- ```js
199
- // vite.config.js
200
- module.exports = {
201
- optimizeDeps: {
202
- include: ["fuzzy"],
203
- },
204
- };
205
- ```
206
-
207
219
  ## TypeScript
208
220
 
209
- Svelte version 3.31 or greater is required if using TypeScript.
221
+ Svelte version 3.31 or greater is required to use this component with TypeScript.
222
+
223
+ TypeScript definitions are located in the [types folder](./types).
210
224
 
211
225
  ## Changelog
212
226