awesomplete
Ultra lightweight, usable, beautiful autocomplete with zero dependencies.
Top Related Projects
typeahead.js is a fast and fully-featured autocomplete library
🔮 Fast and full-featured autocomplete library
Simple autocomplete pure vanilla Javascript library.
Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
Quick Overview
Awesomplete is a lightweight, customizable autocomplete widget with zero dependencies. It's designed to be easy to use and integrate into web projects, providing a simple yet powerful solution for enhancing form inputs with autocomplete functionality.
Pros
- Lightweight and dependency-free, making it easy to integrate into any project
- Highly customizable with various options and styling possibilities
- Supports keyboard navigation and accessibility features
- Works with both static and dynamically loaded data sources
Cons
- Limited built-in features compared to more comprehensive autocomplete libraries
- May require additional coding for complex use cases
- Documentation could be more extensive and provide more examples
- Not actively maintained, with the last major update in 2018
Code Examples
- Basic usage with an array of strings:
new Awesomplete(document.querySelector("input"), {
list: ["Ada", "Java", "JavaScript", "Brainfuck", "LOLCODE", "Node.js", "Ruby on Rails"]
});
- Using a function to generate suggestions:
new Awesomplete(document.querySelector("input"), {
list: function(text) {
return [text + "er", text + "est", text + "s"];
}
});
- Custom item rendering:
new Awesomplete(document.querySelector("input"), {
list: [
{ label: "Belarus", value: "BY" },
{ label: "China", value: "CN" },
{ label: "United States", value: "US" }
],
item: function(text, input) {
return Awesomplete.$.create("li", {
innerHTML: `<strong>${text.label}</strong> (${text.value})`,
"aria-selected": "false"
});
}
});
Getting Started
To use Awesomplete in your project, follow these steps:
- Include the Awesomplete CSS and JavaScript files in your HTML:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/awesomplete@1.1.5/awesomplete.css" />
<script src="https://cdn.jsdelivr.net/npm/awesomplete@1.1.5/awesomplete.min.js" async></script>
- Create an input element and initialize Awesomplete:
<input type="text" id="myInput" />
<script>
document.addEventListener("DOMContentLoaded", function() {
new Awesomplete(document.querySelector("#myInput"), {
list: ["Option 1", "Option 2", "Option 3"]
});
});
</script>
This will create a basic autocomplete input with three options. You can customize the behavior and appearance by adjusting the options passed to the Awesomplete constructor.
Competitor Comparisons
typeahead.js is a fast and fully-featured autocomplete library
Pros of typeahead.js
- More robust and feature-rich, offering advanced functionality like remote data fetching and caching
- Better suited for large datasets and complex autocomplete scenarios
- Provides more customization options and flexibility in styling and behavior
Cons of typeahead.js
- Larger file size and potentially higher performance overhead
- Steeper learning curve due to more complex API and configuration options
- Requires jQuery as a dependency, which may not be ideal for all projects
Code Comparison
Awesomplete:
new Awesomplete(input, {
list: ["Apple", "Banana", "Cherry"]
});
typeahead.js:
$('#input').typeahead({
source: ["Apple", "Banana", "Cherry"]
});
Summary
Awesomplete is a lightweight, dependency-free autocomplete library that's easy to set up and use. It's ideal for simple autocomplete needs and projects where minimalism is preferred.
typeahead.js, on the other hand, offers more advanced features and customization options, making it suitable for complex autocomplete requirements. However, it comes with a larger footprint and requires jQuery.
Choose Awesomplete for simplicity and small projects, and typeahead.js for feature-rich, highly customizable autocomplete functionality in larger applications.
🔮 Fast and full-featured autocomplete library
Pros of Autocomplete
- More comprehensive and feature-rich, offering advanced functionalities like multi-source search and query suggestions
- Better documentation and extensive API, allowing for more customization and integration options
- Active development and regular updates, ensuring compatibility with modern web technologies
Cons of Autocomplete
- Steeper learning curve due to its complexity and extensive features
- Larger file size and potential performance overhead for simpler use cases
- Requires more setup and configuration compared to Awesomplete's plug-and-play approach
Code Comparison
Awesomplete:
new Awesomplete(input, {
list: ["Ada", "Java", "JavaScript", "Brainfuck", "LOLCODE", "Node.js", "Ruby on Rails"]
});
Autocomplete:
autocomplete({
container: '#autocomplete',
getSources({ query }) {
return [{
sourceId: 'products',
getItems() {
return getAlgoliaResults({
searchClient,
queries: [{ indexName: 'products', query }],
});
},
}];
},
});
The code comparison demonstrates the simplicity of Awesomplete's implementation versus the more complex but flexible setup of Autocomplete. Awesomplete requires minimal configuration, while Autocomplete offers more control over data sources and rendering.
Simple autocomplete pure vanilla Javascript library.
Pros of autoComplete.js
- More feature-rich, offering advanced customization options
- Better documentation and examples
- Active development and frequent updates
Cons of autoComplete.js
- Larger file size, potentially impacting page load times
- Steeper learning curve due to more complex API
- May be overkill for simple autocomplete needs
Code Comparison
Awesomplete:
new Awesomplete(input, {
list: ["Ada", "Java", "JavaScript", "Brainfuck", "LOLCODE", "Node.js", "Ruby on Rails"]
});
autoComplete.js:
new autoComplete({
selector: "#autoComplete",
data: {
src: ["Ada", "Java", "JavaScript", "Brainfuck", "LOLCODE", "Node.js", "Ruby on Rails"]
}
});
Both libraries offer simple setup for basic autocomplete functionality. However, autoComplete.js provides more options for customization and data handling, while Awesomplete focuses on simplicity and ease of use.
autoComplete.js is better suited for complex projects requiring advanced features, while Awesomplete is ideal for simpler implementations where a lightweight solution is preferred. The choice between the two depends on the specific needs of your project, considering factors such as required features, performance, and development complexity.
Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
Pros of jQuery-Autocomplete
- More feature-rich, offering advanced functionality like custom data formatting and multiple value selection
- Better integration with jQuery, making it easier to use in jQuery-based projects
- Supports remote data sources, allowing for dynamic data fetching
Cons of jQuery-Autocomplete
- Larger file size and potentially slower performance due to jQuery dependency
- More complex setup and configuration compared to Awesomplete's simplicity
- Less customizable styling options out of the box
Code Comparison
Awesomplete:
new Awesomplete(input, {
list: ["Apple", "Banana", "Cherry"]
});
jQuery-Autocomplete:
$('#input').autocomplete({
lookup: ["Apple", "Banana", "Cherry"],
onSelect: function (suggestion) {
console.log('You selected: ' + suggestion.value);
}
});
Both libraries provide simple ways to create autocomplete functionality, but jQuery-Autocomplete requires jQuery and offers more configuration options. Awesomplete is more lightweight and can be used without any dependencies, making it easier to integrate into various projects. However, jQuery-Autocomplete's advanced features may be beneficial for more complex use cases.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Awesomplete
https://leaverou.github.io/awesomplete/
Awesomplete is an ultra lightweight, customizable, simple autocomplete widget with zero dependencies, built with modern standards for modern browsers.
Installation
There are a few ways to obtain the needed files. Here are 2 of them:
- CDN server
https://cdnjs.com/libraries/awesomplete
- Another way to get up and running is by using
yarn
ornpm
:
yarn add awesomplete
npm install awesomplete --save
More information about the npm package can be found here.
Basic Usage
Before you try anything, you need to include awesomplete.css and awesomplete.js in your page, via the usual tags:
<link rel="stylesheet" href="awesomplete.css" />
<script src="awesomplete.js" async></script>
Then you can add an Awesomplete widget by adding the following input tag:
<input class="awesomplete"
data-list="Ada, Java, JavaScript, Brainfuck, LOLCODE, Node.js, Ruby on Rails" />
Add class="awesomplete"
for it to be automatically processed (you can still specify many options via HTML attributes)
Otherwise you can instantiate with a few lines of JS code, which allow for more customization.
There are many ways to link an input to a list of suggestions. The simple example above could have also been made with the following markup, which provides a nice native fallback in case the script doesnât load:
<input class="awesomplete" list="mylist" />
<datalist id="mylist">
<option>Ada</option>
<option>Java</option>
<option>JavaScript</option>
<option>Brainfuck</option>
<option>LOLCODE</option>
<option>Node.js</option>
<option>Ruby on Rails</option>
</datalist>
Or the following, if you donât want to use a <datalist>
, or if you donât want to use IDs (since any selector will work in data-list):
<input class="awesomplete" data-list="#mylist" />
<ul id="mylist">
<li>Ada</li>
<li>Java</li>
<li>JavaScript</li>
<li>Brainfuck</li>
<li>LOLCODE</li>
<li>Node.js</li>
<li>Ruby on Rails</li>
</ul>
There are multiple customizations and properties able to be instantiated within the JS. Libraries and definitions of the properties are available in the Links below.
Options
JS Property | HTML Attribute | Description | Value | Default |
---|---|---|---|---|
list | data-list | Where to find the list of suggestions. | Array of strings, HTML element, CSS selector (no groups, i.e. no commas), String containing a comma-separated list of items | N/A |
minChars | data-minchars | Minimum characters the user has to type before the autocomplete popup shows up. | Number | 2 |
maxItems | data-maxitems | Maximum number of suggestions to display. | Number | 10 |
autoFirst | data-autofirst | Should the first element be automatically | Boolean | false |
listLabel | data-listlabel | Denotes a label to be used as aria-label on the generated autocomplete list. | String | Results List |
License
Awesomplete is released under the MIT License. See LICENSE file for details.
Links
The official site for the library is at https://leaverou.github.io/awesomplete/.
Documentation for the API and other topics is at https://leaverou.github.io/awesomplete/#api.
Created by Lea Verou and other fantastic contributors.
Top Related Projects
typeahead.js is a fast and fully-featured autocomplete library
🔮 Fast and full-featured autocomplete library
Simple autocomplete pure vanilla Javascript library.
Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot