svelte-typeahead 4.3.2 → 4.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-typeahead",
3
- "version": "4.3.2",
3
+ "version": "4.4.0",
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.49.0",
25
- "svelte-check": "^2.8.0",
22
+ "svelte": "^3.52.0",
23
+ "svelte-check": "^2.9.0",
26
24
  "svelte-readme": "^3.6.3"
27
25
  },
28
26
  "repository": {
@@ -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 = () => (hideDropdown = true);
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
@@ -158,6 +175,7 @@
158
175
  }}
159
176
  />
160
177
 
178
+ <!-- svelte-ignore a11y-role-has-required-aria-props -->
161
179
  <div
162
180
  data-svelte-typeahead
163
181
  bind:this={comboboxRef}
@@ -188,7 +206,7 @@
188
206
  on:focus
189
207
  on:focus={() => {
190
208
  open();
191
- if (showDropdownOnFocus) {
209
+ if (showDropdownOnFocus || showAllResultsOnFocus) {
192
210
  showResults = true;
193
211
  isFocused = true;
194
212
  }
@@ -229,6 +247,7 @@
229
247
  >
230
248
  {#if showResults}
231
249
  {#each results as result, index}
250
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
232
251
  <li
233
252
  role="option"
234
253
  id="{id}-result-{index}"
@@ -270,6 +289,7 @@
270
289
  top: 100%;
271
290
  left: 0;
272
291
  width: 100%;
292
+ margin: 0;
273
293
  padding: 0;
274
294
  list-style: none;
275
295
  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<any>;
97
+ clear: CustomEvent<null>;
92
98
  input: WindowEventMap["input"];
93
99
  change: WindowEventMap["change"];
94
100
  focus: WindowEventMap["focus"];