svelte-typeahead 4.3.2 → 4.4.1
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 +16 -0
- package/README.md +36 -42
- package/lib/index.js +183 -130
- package/lib/index.mjs +183 -130
- package/package.json +3 -5
- package/src/Typeahead.svelte +22 -3
- package/types/Typeahead.svelte.d.ts +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-typeahead",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Accessible, fuzzy search typeahead component",
|
|
6
6
|
"author": "Eric Liu (https://github.com/metonym)",
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
"types": "./types/index.d.ts",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"dev": "rollup -cw",
|
|
13
|
-
"predeploy": "rollup -c",
|
|
14
|
-
"deploy": "npx gh-pages -d dist",
|
|
15
13
|
"prepack": "BUNDLE=true rollup -c",
|
|
16
14
|
"test": "svelte-check --workspace test"
|
|
17
15
|
},
|
|
@@ -21,8 +19,8 @@
|
|
|
21
19
|
},
|
|
22
20
|
"devDependencies": {
|
|
23
21
|
"@rollup/plugin-commonjs": "^21.0.2",
|
|
24
|
-
"svelte": "^3.
|
|
25
|
-
"svelte-check": "^2.
|
|
22
|
+
"svelte": "^3.52.0",
|
|
23
|
+
"svelte-check": "^2.9.0",
|
|
26
24
|
"svelte-readme": "^3.6.3"
|
|
27
25
|
},
|
|
28
26
|
"repository": {
|
package/src/Typeahead.svelte
CHANGED
|
@@ -36,6 +36,9 @@
|
|
|
36
36
|
/** Set to `true` to only show results when the input is focused */
|
|
37
37
|
export let showDropdownOnFocus = false;
|
|
38
38
|
|
|
39
|
+
/** Set to `true` for all results to be shown when an empty input is focused */
|
|
40
|
+
export let showAllResultsOnFocus = false;
|
|
41
|
+
|
|
39
42
|
/**
|
|
40
43
|
* Specify the maximum number of results to return
|
|
41
44
|
* @type {number}
|
|
@@ -134,7 +137,10 @@
|
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
const open = () => (hideDropdown = false);
|
|
137
|
-
const close = () =>
|
|
140
|
+
const close = () => {
|
|
141
|
+
hideDropdown = true;
|
|
142
|
+
isFocused = false;
|
|
143
|
+
};
|
|
138
144
|
|
|
139
145
|
$: options = { pre: "<mark>", post: "</mark>", extract };
|
|
140
146
|
$: results = fuzzy
|
|
@@ -148,6 +154,17 @@
|
|
|
148
154
|
$: if (showDropdownOnFocus) {
|
|
149
155
|
showResults = showResults && isFocused;
|
|
150
156
|
}
|
|
157
|
+
$: if (isFocused && showAllResultsOnFocus && value.length === 0) {
|
|
158
|
+
results = data
|
|
159
|
+
.filter((datum) => !filter(datum))
|
|
160
|
+
.map((original, index) => ({
|
|
161
|
+
disabled: disable(original),
|
|
162
|
+
index,
|
|
163
|
+
original,
|
|
164
|
+
score: 0,
|
|
165
|
+
string: extract(original),
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
151
168
|
</script>
|
|
152
169
|
|
|
153
170
|
<svelte:window
|
|
@@ -163,7 +180,7 @@
|
|
|
163
180
|
bind:this={comboboxRef}
|
|
164
181
|
role="combobox"
|
|
165
182
|
aria-haspopup="listbox"
|
|
166
|
-
aria-
|
|
183
|
+
aria-controls="{id}-listbox"
|
|
167
184
|
class:dropdown={results.length > 0}
|
|
168
185
|
aria-expanded={showResults}
|
|
169
186
|
id="{id}-typeahead"
|
|
@@ -188,7 +205,7 @@
|
|
|
188
205
|
on:focus
|
|
189
206
|
on:focus={() => {
|
|
190
207
|
open();
|
|
191
|
-
if (showDropdownOnFocus) {
|
|
208
|
+
if (showDropdownOnFocus || showAllResultsOnFocus) {
|
|
192
209
|
showResults = true;
|
|
193
210
|
isFocused = true;
|
|
194
211
|
}
|
|
@@ -229,6 +246,7 @@
|
|
|
229
246
|
>
|
|
230
247
|
{#if showResults}
|
|
231
248
|
{#each results as result, index}
|
|
249
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
232
250
|
<li
|
|
233
251
|
role="option"
|
|
234
252
|
id="{id}-result-{index}"
|
|
@@ -270,6 +288,7 @@
|
|
|
270
288
|
top: 100%;
|
|
271
289
|
left: 0;
|
|
272
290
|
width: 100%;
|
|
291
|
+
margin: 0;
|
|
273
292
|
padding: 0;
|
|
274
293
|
list-style: none;
|
|
275
294
|
background-color: inherit;
|
|
@@ -68,6 +68,12 @@ export interface TypeaheadProps<TItem> extends SearchProps {
|
|
|
68
68
|
*/
|
|
69
69
|
showDropdownOnFocus?: boolean;
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Set to `true` for all results to be shown when an empty input is focused
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
showAllResultsOnFocus?: boolean;
|
|
76
|
+
|
|
71
77
|
/**
|
|
72
78
|
* Specify the maximum number of results to return
|
|
73
79
|
* @default Infinity
|
|
@@ -88,7 +94,7 @@ export default class Typeahead<
|
|
|
88
94
|
originalIndex: number;
|
|
89
95
|
}>;
|
|
90
96
|
type: CustomEvent<string>;
|
|
91
|
-
clear: CustomEvent<
|
|
97
|
+
clear: CustomEvent<null>;
|
|
92
98
|
input: WindowEventMap["input"];
|
|
93
99
|
change: WindowEventMap["change"];
|
|
94
100
|
focus: WindowEventMap["focus"];
|