svelte-typeahead 4.2.1 → 4.2.4

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.2.1",
3
+ "version": "4.2.4",
4
4
  "license": "MIT",
5
5
  "description": "Accessible, fuzzy search typeahead component",
6
6
  "author": "Eric Liu (https://github.com/metonym)",
@@ -21,10 +21,10 @@
21
21
  "svelte-search": "^1.1.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@rollup/plugin-commonjs": "^21.0.1",
25
- "svelte": "^3.44.0",
26
- "svelte-check": "^2.2.6",
27
- "svelte-readme": "^3.4.1"
24
+ "@rollup/plugin-commonjs": "^21.0.2",
25
+ "svelte": "^3.48.0",
26
+ "svelte-check": "^2.8.0",
27
+ "svelte-readme": "^3.6.3"
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",
@@ -92,7 +92,9 @@
92
92
  /** @type {(direction: -1 | 1) => void} */
93
93
  function change(direction) {
94
94
  let index =
95
- selectedIndex === results.length - 1 ? 0 : selectedIndex + direction;
95
+ direction === 1 && selectedIndex === results.length - 1
96
+ ? 0
97
+ : selectedIndex + direction;
96
98
  if (index < 0) index = results.length - 1;
97
99
 
98
100
  let disabled = results[index].disabled;
@@ -118,6 +120,7 @@
118
120
  .filter((result) => !filter(result.original))
119
121
  .map((result) => ({ ...result, disabled: disable(result.original) }));
120
122
  $: resultsId = results.map((result) => extract(result.original)).join("");
123
+ $: showResults = !hideDropdown && results.length > 0;
121
124
  </script>
122
125
 
123
126
  <svelte:window
@@ -135,7 +138,7 @@
135
138
  aria-haspopup="listbox"
136
139
  aria-owns="{id}-listbox"
137
140
  class:dropdown={results.length > 0}
138
- aria-expanded={!hideDropdown && results.length > 0}
141
+ aria-expanded={showResults}
139
142
  id="{id}-typeahead"
140
143
  >
141
144
  <Search
@@ -195,22 +198,25 @@
195
198
  aria-labelledby="{id}-label"
196
199
  id="{id}-listbox"
197
200
  >
198
- {#if !hideDropdown && results.length > 0}
199
- {#each results as result, i}
201
+ {#if showResults}
202
+ {#each results as result, index}
200
203
  <li
201
204
  role="option"
202
- id="{id}-result-{i}"
203
- class:selected={selectedIndex === i}
205
+ id="{id}-result-{index}"
206
+ class:selected={selectedIndex === index}
204
207
  class:disabled={result.disabled}
205
- aria-selected={selectedIndex === i}
208
+ aria-selected={selectedIndex === index}
206
209
  on:click={() => {
207
- if (!result.disabled) {
208
- selectedIndex = i;
209
- select();
210
- }
210
+ if (result.disabled) return;
211
+ selectedIndex = index;
212
+ select();
213
+ }}
214
+ on:mouseenter={() => {
215
+ if (result.disabled) return;
216
+ selectedIndex = index;
211
217
  }}
212
218
  >
213
- <slot {result} index={i} {value}>
219
+ <slot {result} {index} {value}>
214
220
  {@html result.string}
215
221
  </slot>
216
222
  </li>
@@ -241,6 +247,10 @@
241
247
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
242
248
  }
243
249
 
250
+ [aria-expanded="true"] ul {
251
+ z-index: 1;
252
+ }
253
+
244
254
  li,
245
255
  .no-results {
246
256
  padding: 0.25rem 1rem;