@itrocks/autocomplete 0.0.2 → 0.0.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/autocomplete.css +4 -0
- package/autocomplete.d.ts +1 -0
- package/autocomplete.js +17 -7
- package/package.json +2 -2
package/autocomplete.css
CHANGED
package/autocomplete.d.ts
CHANGED
package/autocomplete.js
CHANGED
|
@@ -83,12 +83,15 @@ export class AutoComplete {
|
|
|
83
83
|
}
|
|
84
84
|
keyDown(event) {
|
|
85
85
|
const suggestions = this.suggestions;
|
|
86
|
-
if (suggestions.
|
|
86
|
+
if (!suggestions.isVisible()) {
|
|
87
|
+
if (suggestions.length > 1) {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
suggestions.show();
|
|
90
|
+
}
|
|
87
91
|
return;
|
|
88
92
|
}
|
|
89
93
|
event.preventDefault();
|
|
90
|
-
if (
|
|
91
|
-
suggestions.show();
|
|
94
|
+
if (suggestions.isLastSelected()) {
|
|
92
95
|
return;
|
|
93
96
|
}
|
|
94
97
|
this.suggest(suggestions.selectNext()?.caption);
|
|
@@ -177,6 +180,7 @@ export class AutoComplete {
|
|
|
177
180
|
}
|
|
178
181
|
class Suggestions {
|
|
179
182
|
combo;
|
|
183
|
+
length = 0;
|
|
180
184
|
list;
|
|
181
185
|
constructor(combo) {
|
|
182
186
|
this.combo = combo;
|
|
@@ -256,13 +260,11 @@ class Suggestions {
|
|
|
256
260
|
return this.createList();
|
|
257
261
|
}
|
|
258
262
|
update(suggestions) {
|
|
259
|
-
if (!suggestions.length) {
|
|
260
|
-
return this.hide();
|
|
261
|
-
}
|
|
262
263
|
let hasSelected = false;
|
|
263
|
-
const list = this.
|
|
264
|
+
const list = this.list ?? this.createList();
|
|
264
265
|
const selected = list.querySelector('li.selected')?.innerText;
|
|
265
266
|
list.innerHTML = '';
|
|
267
|
+
this.length = suggestions.length;
|
|
266
268
|
for (const suggestion of suggestions) {
|
|
267
269
|
const item = document.createElement('li');
|
|
268
270
|
item.dataset.id = '' + suggestion.id;
|
|
@@ -276,5 +278,13 @@ class Suggestions {
|
|
|
276
278
|
if (!hasSelected) {
|
|
277
279
|
list.firstElementChild?.classList.add('selected');
|
|
278
280
|
}
|
|
281
|
+
if (this.length > 1) {
|
|
282
|
+
if (!this.isVisible())
|
|
283
|
+
this.show();
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
if (this.isVisible())
|
|
287
|
+
this.hide();
|
|
288
|
+
}
|
|
279
289
|
}
|
|
280
290
|
}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@types/node": "^22.9",
|
|
9
9
|
"sass": "^1.83",
|
|
10
|
-
"typescript": "5.
|
|
10
|
+
"typescript": "~5.8"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"LICENSE",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
42
|
"types": "./autocomplete.d.ts",
|
|
43
|
-
"version": "0.0.
|
|
43
|
+
"version": "0.0.4"
|
|
44
44
|
}
|