-
-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathllms-full.txt
More file actions
921 lines (723 loc) · 27.8 KB
/
llms-full.txt
File metadata and controls
921 lines (723 loc) · 27.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
# autoComplete.js
> Simple, lightweight, pure vanilla Javascript autocomplete library. Zero dependencies. Designed for speed, high versatility, and seamless integration with a wide range of projects and systems.
autoComplete.js is a progressively designed autocomplete/autosuggest library that works on `<input>`, `<textarea>`, and `contentEditable` elements. It features a powerful search engine with strict and loose matching modes, diacritics support, WAI-ARIA accessibility, lifecycle events, and a fully customizable API. The library has zero runtime dependencies and ships at ~9 KB minified (~3.7 KB gzipped).
## Docs
- [Installation](https://tarekraafat.github.io/autoComplete.js/#/installation): Package manager (npm, yarn), CDN (jsDelivr, cdnjs, unpkg), and direct download options
- [Getting Started](https://tarekraafat.github.io/autoComplete.js/#/getting-started): Quick start guide for beginners to advanced developers
- [Usage](https://tarekraafat.github.io/autoComplete.js/#/usage): Step-by-step usage guide with HTML, script, and style setup
- [Configuration](https://tarekraafat.github.io/autoComplete.js/#/configuration): Full API reference for options, methods, and events
- [How-to Guides](https://tarekraafat.github.io/autoComplete.js/#/how-to-guides): Practical recipes and real-world usage patterns
- [FAQ](https://tarekraafat.github.io/autoComplete.js/#/faq): Frequently asked questions
- [Styles](https://tarekraafat.github.io/autoComplete.js/#/styles): Available stylesheets and customization
- [Playground](https://tarekraafat.github.io/autoComplete.js/#/playground): Interactive demo
- [Comparison](https://tarekraafat.github.io/autoComplete.js/#/comparison): How autoComplete.js compares to other autocomplete libraries
- [Used By](https://tarekraafat.github.io/autoComplete.js/#/used-by): Projects and organizations using autoComplete.js in production
- [Release Notes](https://tarekraafat.github.io/autoComplete.js/#/release-notes): Full changelog and versioning guidelines
- [Live Demo](https://tarekraafat.github.io/autoComplete.js/demo/): Working demo with real data
- [Roadmap](https://github.com/TarekRaafat/autoComplete.js/blob/master/ROADMAP.md): Planned releases from v10.3.0 through v11.1.0
- [GitHub](https://github.com/TarekRaafat/autoComplete.js): Source code, issues, and contributions
## Installation
npm:
```
npm i @tarekraafat/autocomplete.js
```
yarn:
```
yarn add @tarekraafat/autocomplete.js
```
CDN (jsDelivr):
```html
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@latest/dist/autoComplete.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@latest/dist/css/autoComplete.min.css">
```
CDN (cdnjs):
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/tarekraafat-autocomplete.js/latest/autoComplete.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tarekraafat-autocomplete.js/latest/css/autoComplete.min.css">
```
CDN (unpkg):
```html
<script src="https://unpkg.com/@tarekraafat/autocomplete.js@latest/dist/autoComplete.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@tarekraafat/autocomplete.js@latest/dist/css/autoComplete.css">
```
ES module import:
```js
import autoComplete from "@tarekraafat/autocomplete.js";
```
CommonJS require:
```js
const autoComplete = require("@tarekraafat/autocomplete.js");
```
## Quick Start
```html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@latest/dist/css/autoComplete.min.css">
</head>
<body>
<div class="autoComplete_wrapper">
<input id="autoComplete" type="search" dir="ltr" spellcheck="false" autocorrect="off" autocomplete="off" autocapitalize="off">
</div>
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@latest/dist/autoComplete.min.js"></script>
<script>
const autoCompleteJS = new autoComplete({
placeHolder: "Search for Food...",
data: {
src: ["Sauce - Thousand Island", "Wild Boar - Tenderloin", "Goat - Whole Cut"],
cache: true,
},
resultItem: {
highlight: true
},
events: {
input: {
selection: (event) => {
const selection = event.detail.selection.value;
autoCompleteJS.input.value = selection;
}
}
}
});
</script>
</body>
</html>
```
## Configuration Options (Detailed)
### selector (optional)
Points to the input, textarea, or contentEditable element.
- Type: `String` (CSS selector) or `Function` (returns Element)
- Default: `"#autoComplete"`
```js
// String selector
selector: "#autoComplete",
// Function selector
selector: () => {
return document.querySelector("#autoComplete");
},
```
### name (optional)
Prefix for all generated class and id names.
- Type: `String`
- Default: `"autoComplete"`
### wrapper (optional)
Wraps the input element in a `<div>` with WAI-ARIA `role="combobox"` attributes.
- Type: `Boolean`
- Default: `true`
Set to `false` if the wrapper breaks your CSS layout. The ARIA attributes will be applied directly to the input element instead.
### data (required)
Data source configuration.
- Type: `Object`
Properties:
- `data.src` (required): `Array` or `Function` returning `Array`. The data source. If a function, it receives the current query as a parameter.
- `data.keys` (required for object arrays): `Array` of strings. Which object keys to search.
- `data.cache` (optional): `Boolean`. Default: `false`. If true, fetches data once at init and reuses it. If false, calls `data.src` on every search trigger.
- `data.filter` (optional): `Function` receiving `Array` of matches, must return `Array`. Custom filter/sort applied before rendering.
```js
// Static string array
data: {
src: ["Apple", "Banana", "Cherry"],
}
// Static object array
data: {
src: [
{ name: "Apple", category: "Fruit" },
{ name: "Carrot", category: "Vegetable" },
],
keys: ["name", "category"],
}
// Async function
data: {
src: async (query) => {
try {
const response = await fetch(`https://api.example.com/search?q=${query}`);
return await response.json();
} catch (error) {
return error;
}
},
keys: ["name"],
cache: false,
}
// With custom filter/sort
data: {
src: ["Apple", "Banana", "Cherry"],
filter: (matches) => {
return matches.sort((a, b) => a.match.length - b.match.length);
},
}
```
### trigger (optional)
Custom condition that determines whether autoComplete.js should start searching.
- Type: `Function` returning `Boolean`. Receives `(query)`.
- Default: Returns true if input is not empty and length >= threshold.
```js
trigger: (query) => {
return query.replace(/ /g, "").length >= 2;
},
```
### query (optional)
Transform the raw input value before searching. Useful for trimming, normalizing, or removing unwanted characters.
- Type: `Function` returning `String`. Receives `(input)`.
- Default: Returns raw input value.
```js
query: (input) => {
return input.replace("pizza", "burger");
},
```
### placeHolder (optional)
Placeholder text for the input element.
- Type: `String`
- Default: none
### threshold (optional)
Minimum number of characters required before triggering search.
- Type: `Integer`
- Default: `1`
Set to `0` to allow triggering with an empty input (useful for "show all on focus" pattern).
### debounce (optional)
Delay in milliseconds after typing stops before triggering search. Useful for reducing API calls with async data sources.
- Type: `Integer`
- Default: `0`
```js
debounce: 300, // Wait 300ms after last keystroke
```
### searchEngine (optional)
Search algorithm to use.
- Type: `String` or `Function`
- Default: `"strict"`
Built-in modes:
- `"strict"`: Substring matching using indexOf. "app" matches "Apple" and "Pineapple".
- `"loose"`: Scattered character matching. All query characters must appear in order but can be non-contiguous. "ae" matches "Apple" (A...lE).
Custom function:
```js
searchEngine: (query, record) => {
// Return the record string if it matches, or undefined if not
if (record.toLowerCase().startsWith(query.toLowerCase())) {
return record;
}
},
```
### diacritics (optional)
Enable Unicode normalization for accent-insensitive search. When enabled, "cafe" matches "cafe" with accented characters.
- Type: `Boolean`
- Default: `false`
Uses `String.normalize("NFD")` to decompose characters and removes combining diacritical marks (U+0300 through U+036F).
### resultsList (optional)
Configuration for the results list container element.
- Type: `Object` or `Boolean` (set to `false` to disable list rendering entirely)
Properties:
- `tag`: `String`. Default: `"ul"`. HTML tag for the list container.
- `id`: `String`. Default: `"autoComplete_list_[instanceId]"`.
- `class`: `String`. CSS class(es) for the list container.
- `destination`: `String` (selector) or `Function`. Default: same as `selector`. Where to insert the list.
- `position`: `String`. Default: `"afterend"`. insertAdjacentElement position relative to destination.
- `element`: `Function(list, data)`. Callback to modify the list element before display. `data` contains `{ query, matches, results }`.
- `maxResults`: `Integer`. Default: `5`. Maximum number of result items to render.
- `tabSelect`: `Boolean`. Default: `false`. Allow Tab key to select the currently highlighted item.
- `noResults`: `Boolean`. Default: `false`. Render the list even when there are zero matches.
### resultItem (optional)
Configuration for each result item element.
- Type: `Object`
Properties:
- `tag`: `String`. Default: `"li"`. HTML tag for each result.
- `id`: `String`. Default: `"autoComplete_result"`. ID prefix (appended with _0, _1, etc.).
- `class`: `String`. CSS class(es) for each result item.
- `element`: `Function(item, data)`. Callback to modify each item before display. `data` contains `{ match, value, key }`.
- `highlight`: `Boolean` or `String`. Default: `false`. Set to `true` to wrap matching characters in `<mark>` elements, or provide a CSS class string for the mark elements.
- `selected`: `String`. CSS class(es) added to the item currently highlighted via keyboard navigation.
### submit (optional)
Controls whether pressing Enter submits the form or is intercepted by autoComplete.js.
- Type: `Boolean`
- Default: `false` (Enter is intercepted and selects the highlighted item)
Set to `true` to allow default Enter behavior (form submission).
### events (optional)
Custom event handlers for the input element and results list. Can add new events or override internal defaults.
- Type: `Object`
- Default internal events:
- input: `input` (triggers search), `keydown` (keyboard navigation), `blur` (closes list)
- list: `mousedown` (prevents blur), `click` (item selection)
```js
events: {
input: {
focus: (event) => {
console.log("Input focused!");
},
},
list: {
scroll: (event) => {
console.log("List scrolled!");
},
},
},
```
If you provide a handler with the same name as an internal event (e.g., `keydown`), your handler replaces the internal one.
## API Methods
### init()
Re-initialize the instance. Sets up ARIA attributes, creates the wrapper and list elements, attaches event listeners, and prefetches data if caching is enabled.
```js
autoCompleteJS.init();
```
### start(query)
Trigger the search pipeline manually. Optionally pass a custom query string instead of reading the input value.
```js
autoCompleteJS.start(); // Uses current input value
autoCompleteJS.start("tea"); // Uses "tea" as the query
```
### unInit()
Destroy the instance. Removes the wrapper element, detaches all event listeners, and cleans up.
```js
autoCompleteJS.unInit();
```
### open()
Open the results list if it has content.
```js
autoCompleteJS.open();
```
### close()
Close the results list.
```js
autoCompleteJS.close();
```
### goTo(index)
Navigate to a specific result item by its index. Wraps around (last+1 goes to first, first-1 goes to last).
```js
autoCompleteJS.goTo(0); // Go to first result
autoCompleteJS.goTo(4); // Go to fifth result
```
### next()
Navigate to the next result item.
```js
autoCompleteJS.next();
```
### previous()
Navigate to the previous result item.
```js
autoCompleteJS.previous();
```
### select(index)
Select a result item. If no index is provided, selects the currently highlighted item.
```js
autoCompleteJS.select(); // Select current cursor position
autoCompleteJS.select(2); // Select third item
```
### search(query, record, options)
Direct access to the search engine for external use.
```js
const result = autoCompleteJS.search("app", "Apple", {
mode: "strict",
diacritics: false,
highlight: true,
});
// Returns: "<mark>App</mark>le"
```
## Events (Detailed)
All events are dispatched as CustomEvent on the input element. Listen with standard `addEventListener`. The `event.detail` property carries the feedback data object.
### Feedback Object Structure
The feedback object (`event.detail`) contains different data depending on the event:
After `response` event:
```js
event.detail = rawDataArray // The array returned from data.src
```
After `results` event:
```js
event.detail = {
query: "app", // The processed search query
matches: [...], // All matching results (before maxResults limit)
results: [...], // Matches sliced to maxResults
}
```
Each match/result entry:
```js
{
match: "Apple", // The matched string (with <mark> highlights if enabled)
value: originalDataEntry, // The original data record
key: "name", // Only present for object data with keys
}
```
After `selection` or `navigate` events:
```js
event.detail = {
query: "app",
matches: [...],
results: [...],
cursor: 0, // Current highlighted index
selection: { // The selected/navigated item
index: 0,
match: "Apple",
value: originalDataEntry,
key: "name",
},
event: MouseEvent/KeyboardEvent, // The triggering DOM event (selection only)
}
```
### Event List
**init**: Fires after initialization is complete.
```js
document.querySelector("#autoComplete").addEventListener("init", function (event) {
console.log("autoComplete.js is ready");
});
```
**response**: Fires after data is fetched from the source.
```js
document.querySelector("#autoComplete").addEventListener("response", function (event) {
console.log("Data received:", event.detail);
});
```
**results**: Fires after search matching is done, before rendering.
```js
document.querySelector("#autoComplete").addEventListener("results", function (event) {
console.log("Query:", event.detail.query);
console.log("Matches:", event.detail.matches.length);
console.log("Displayed:", event.detail.results.length);
});
```
**open**: Fires after the results list opens.
```js
document.querySelector("#autoComplete").addEventListener("open", function (event) {
console.log("Results list opened");
});
```
**navigate**: Fires on each keyboard navigation step (arrow up/down).
```js
document.querySelector("#autoComplete").addEventListener("navigate", function (event) {
console.log("Navigated to:", event.detail.selection.value);
});
```
**selection**: Fires when a result item is selected (Enter, Tab, or mouse click).
```js
document.querySelector("#autoComplete").addEventListener("selection", function (event) {
const feedback = event.detail;
autoCompleteJS.input.value = feedback.selection.value;
console.log("Selected:", feedback.selection);
});
```
**close**: Fires after the results list closes.
```js
document.querySelector("#autoComplete").addEventListener("close", function (event) {
console.log("Results list closed");
});
```
**clear**: Fires after the input is cleared (Escape key).
```js
document.querySelector("#autoComplete").addEventListener("clear", function (event) {
console.log("Input cleared");
});
```
## Common Patterns
### Async Data Source
```js
const autoCompleteJS = new autoComplete({
data: {
src: async (query) => {
try {
const response = await fetch(`https://api.example.com/search?q=${query}`);
const data = await response.json();
return data;
} catch (error) {
return error;
}
},
keys: ["name"],
cache: false,
},
debounce: 300,
resultItem: {
highlight: true
}
});
```
### Handling Selection (String Data)
```js
document.querySelector("#autoComplete").addEventListener("selection", function (event) {
autoCompleteJS.input.value = event.detail.selection.value;
});
```
### Handling Selection (Object Data with Keys)
```js
document.querySelector("#autoComplete").addEventListener("selection", function (event) {
const feedback = event.detail;
const selection = feedback.selection.value[feedback.selection.key];
autoCompleteJS.input.value = selection;
});
```
### No Results Message
```js
const autoCompleteJS = new autoComplete({
data: {
src: ["Apple", "Banana", "Cherry"],
},
resultsList: {
noResults: true,
element: (list, data) => {
if (!data.results.length) {
const message = document.createElement("div");
message.setAttribute("class", "no_result");
message.innerHTML = `Found no results for "${data.query}"`;
list.prepend(message);
}
},
},
});
```
### Custom Result Item Rendering
```js
const autoCompleteJS = new autoComplete({
data: {
src: [
{ name: "Apple", category: "Fruit" },
{ name: "Carrot", category: "Vegetable" },
],
keys: ["name"],
},
resultItem: {
element: (item, data) => {
item.innerHTML = `
<span>${data.match}</span>
<span style="color: gray; font-size: 0.8em;">${data.value.category}</span>
`;
},
},
});
```
### Show All Results on Focus
```js
const autoCompleteJS = new autoComplete({
data: {
src: ["Apple", "Banana", "Cherry", "Date", "Elderberry"],
cache: true,
},
threshold: 0,
resultItem: {
highlight: true
},
events: {
input: {
focus() {
autoCompleteJS.start();
},
},
},
});
```
### Force Selection from List
```js
const autoCompleteJS = new autoComplete({
data: {
src: ["Apple", "Banana", "Cherry"],
cache: true,
},
events: {
input: {
blur() {
if (!autoCompleteJS.data.store.includes(autoCompleteJS.input.value)) {
autoCompleteJS.input.value = "";
}
},
selection(event) {
autoCompleteJS.input.value = event.detail.selection.value;
},
},
},
});
```
### Multiple Instances
```js
const searchOne = new autoComplete({
selector: "#search-one",
data: { src: ["Apple", "Banana"] },
});
const searchTwo = new autoComplete({
selector: "#search-two",
data: { src: ["Red", "Blue", "Green"] },
});
```
### Dynamic Data / Runtime Updates
```js
// With cache: false (default), data.src is called on every search
const autoCompleteJS = new autoComplete({
data: {
src: async (query) => {
// This runs on every keystroke, always fetching fresh data
const response = await fetch(`/api/search?q=${query}`);
return await response.json();
},
},
});
// With cache: true, update the store directly
autoCompleteJS.data.store = newDataArray;
```
### Disabling the Wrapper
```js
// If the auto-generated wrapper div breaks your CSS layout
const autoCompleteJS = new autoComplete({
wrapper: false,
data: {
src: ["Apple", "Banana", "Cherry"],
},
});
```
### Using with Form Submit
```js
const autoCompleteJS = new autoComplete({
submit: true, // Allow Enter to submit the form
data: {
src: ["Apple", "Banana", "Cherry"],
},
});
```
### Input Sanitization (Security)
```js
// Using DOMPurify to sanitize input before searching
const autoCompleteJS = new autoComplete({
query: (input) => {
return DOMPurify.sanitize(input);
},
data: {
src: ["Apple", "Banana", "Cherry"],
},
});
```
### Custom Search Engine (Fuse.js Integration)
Use any external search library by passing a custom function to `searchEngine`. This example uses Fuse.js for weighted fuzzy matching with relevance scoring. Fuse.js is a separate dependency, not part of autoComplete.js.
```js
import Fuse from "fuse.js";
const data = [
{ name: "Apple", category: "Fruit" },
{ name: "Carrot", category: "Vegetable" },
];
const fuse = new Fuse(data, {
keys: [{ name: "name", weight: 2 }, { name: "category", weight: 1 }],
threshold: 0.4,
includeScore: true,
});
const autoCompleteJS = new autoComplete({
data: {
src: data,
keys: ["name"],
filter: (list) => {
const results = fuse.search(autoCompleteJS.input.value);
return results.map((r) => list.find((item) => item.value === r.item)).filter(Boolean);
},
},
searchEngine: (query, record) => {
if (record.toLowerCase().includes(query.toLowerCase())) return record;
},
});
```
### Searching Across Multiple Keys
```js
const autoCompleteJS = new autoComplete({
data: {
src: [
{ name: "Apple", category: "Fruit" },
{ name: "Carrot", category: "Vegetable" },
],
keys: ["name", "category"],
},
resultItem: {
element: (item, data) => {
item.innerHTML = `
<span>${data.match}</span>
<span style="color: gray; font-size: 0.8em;">in ${data.key}</span>
`;
},
},
});
```
## FAQ
### How do I get the selected value?
Listen for the `selection` event. For string data: `event.detail.selection.value`. For object data: `event.detail.selection.value[event.detail.selection.key]`.
### How do I show all results when the input is focused?
Set `threshold: 0` and call `autoCompleteJS.start()` in a `focus` event handler.
### How do I use multiple autocomplete inputs on the same page?
Create separate `autoComplete` instances with unique `selector` values. Class selectors only match the first element.
### How do I fetch data from an API?
Use an async function as `data.src`. It receives the query as a parameter. Set `debounce: 300` to reduce API calls.
### How do I update the data source at runtime?
With `cache: false` (default), `data.src` is called on every search. With `cache: true`, update `autoCompleteJS.data.store` directly.
### How do I force the user to select from the list?
Validate the input value on the `blur` event and clear it if it doesn't match any entry in the data store.
### How do I show a "No Results" message?
Enable `resultsList.noResults: true` and use `resultsList.element` to prepend a message when `data.results.length` is 0.
### How do I disable the wrapper?
Set `wrapper: false`. ARIA attributes will be applied directly to the input.
### How do I search across multiple keys?
Pass multiple keys in `data.keys`: `keys: ["name", "category"]`.
### How do I customize result item appearance?
Use `resultItem.element` callback: `element: (item, data) => { item.innerHTML = "..."; }`.
### How do I allow Enter to submit the form?
Set `submit: true` in the configuration.
## ARIA Accessibility
autoComplete.js implements the WAI-ARIA 1.2 combobox pattern for screen reader and keyboard accessibility.
### ARIA Attributes
When `wrapper: true` (default):
- Wrapper `<div>`: `role="combobox"`, `aria-owns` (list ID), `aria-haspopup="true"`, `aria-expanded` (true/false)
- Input element: `aria-controls` (list ID), `aria-autocomplete="both"`, `aria-activedescendant` (active item ID)
- Results list: `role="listbox"`, `hidden` attribute
- Result items: `role="option"`, `aria-selected` (true/false)
When `wrapper: false`, the combobox ARIA attributes (`aria-owns`, `aria-haspopup`, `aria-expanded`) are applied directly to the input element.
### Keyboard Navigation
- Arrow Down: Move to next result (wraps to first)
- Arrow Up: Move to previous result (wraps to last)
- Enter: Select highlighted result
- Tab: Select highlighted result (when `resultsList.tabSelect: true`)
- Escape: Close results list and clear input
All keyboard interactions update `aria-activedescendant`, `aria-selected`, and `aria-expanded` in real time.
### Screen Reader Behavior
The combobox pattern ensures screen readers announce:
- The input role and autocomplete capability
- When the results list opens or closes (via `aria-expanded`)
- Which result item is currently highlighted (via `aria-activedescendant`)
- The total number of available options (via the listbox role)
## Features
- Pure vanilla JavaScript, zero dependencies
- ~9 KB minified, ~3.7 KB gzipped
- Two search modes: strict (substring) and loose (scattered character)
- Diacritics/accent-insensitive search
- Async data sources via Promises or async/await
- Data caching
- Debounce support
- WAI-ARIA 1.2 compliant (combobox + listbox pattern)
- Keyboard navigation (Arrow keys, Enter, Tab, Escape)
- Highlight matching characters
- Works on input, textarea, and contentEditable elements
- Customizable result list and item rendering
- Lifecycle events for full control
- Multiple instances support
## Comparison
| Library | Size (gzip) | Dependencies | Framework | Drop-in | WAI-ARIA |
|---------|-------------|--------------|-----------|---------|----------|
| **autoComplete.js** | **~3.7 KB** | **0** | **None (vanilla JS)** | **Yes** | **Yes** |
| Downshift | ~8 KB | 5 | React only | No | Yes |
| Tom Select | ~16 KB | 1 | None | Yes | Partial |
| Select2 | ~17 KB | jQuery | jQuery | Yes | Partial |
| Choices.js | ~20 KB | 0 | None | Yes | Partial |
| Algolia Autocomplete | ~25 KB | 5 | Any (Preact core) | Yes | Yes |
| react-select | ~27 KB | 9 | React only | Yes | Yes |
autoComplete.js is the smallest option in the category: zero dependencies, full WAI-ARIA 1.2 compliance, async data, debounce, lifecycle events, and custom search engine support.
## Used By
autoComplete.js is used by 2,400+ projects across many industries. Notable adopters include:
- IBM Carbon: IBM's open source design system (Enterprise)
- The Guardian: British daily newspaper interactive articles (Media)
- Snapcraft (Canonical): Ubuntu Snap Store website (Developer Tools)
- Weblate: Web-based continuous localization platform (Localization)
- Blockscout: Blockchain explorer for Ethereum-based networks (Blockchain)
- Decidim: Participatory democracy platform (Government)
- Eclipse Ditto: IoT digital twins framework, Eclipse Foundation (IoT)
- dotCMS: Enterprise content management system (Enterprise)
- Chocolatey: Windows package manager website (Developer Tools)
- transport.data.gouv.fr: French national transport open data platform (Government)
- ONRR.gov: U.S. Department of the Interior website (Government)
- Hitobito: Swiss association management platform, 1.2M+ members (Community)
- inovex Elements: UI component library for Angular, React, Vue (Design Systems)
- Solid Design System: Design system built on web components (Design Systems)
- Yasgui: SPARQL query editor for semantic web (Linked Data)
- LiveCodes: Client-side code playground, 80+ languages (Developer Tools)
- CircuitVerse: Digital logic circuit simulator platform (Education)
- Proximi.io: Indoor positioning and wayfinding platform (Geolocation)
- Netframe: Open source collaborative platform (Collaboration)
- SenX Discovery: Dashboard widgets for Warp 10 time series (IoT)
- initiative.sh: Web-based tools for tabletop RPG game masters (Gaming)
Full list: https://github.com/TarekRaafat/autoComplete.js/network/dependents
## License
Apache 2.0