Top Related Projects
🔮 Fast and full-featured autocomplete library
Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
Ultra lightweight, usable, beautiful autocomplete with zero dependencies.
Simple autocomplete pure vanilla Javascript library.
Quick Overview
Typeahead.js is a fast and feature-rich autocomplete library for JavaScript. It provides flexible and customizable typeahead functionality, allowing users to quickly find and select from a list of suggestions as they type. The library is designed to be lightweight and easy to integrate into web applications.
Pros
- Fast and efficient, with built-in caching and rate limiting
- Highly customizable, allowing for custom templates and styling
- Supports both local and remote data sources
- Works well with various JavaScript frameworks and libraries
Cons
- No longer actively maintained (last update was in 2017)
- Limited built-in accessibility features
- May require additional setup for more complex use cases
- Some users report issues with newer browser versions
Code Examples
- Basic usage with local data:
$('#search-input').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: substringMatcher(states)
});
- Remote data source:
var bloodhound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/search?q=%QUERY',
wildcard: '%QUERY'
}
});
$('#remote-search').typeahead(null, {
name: 'best-pictures',
display: 'name',
source: bloodhound
});
- Custom templates:
$('#custom-templates').typeahead(null, {
name: 'best-pictures',
display: 'value',
source: bestPictures,
templates: {
empty: [
'<div class="empty-message">',
'Unable to find any Best Picture winners that match the current query',
'</div>'
].join('\n'),
suggestion: Handlebars.compile('<div><strong>{{value}}</strong> – {{year}}</div>')
}
});
Getting Started
- Include jQuery and Typeahead.js in your HTML:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.min.js"></script>
- Initialize Typeahead on an input field:
$('#search-input').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: substringMatcher(['Alabama', 'Alaska', 'Arizona', ...])
});
- Style the Typeahead dropdown using CSS:
.tt-menu {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: 0 5px 10px rgba(0,0,0,.2);
}
Competitor Comparisons
🔮 Fast and full-featured autocomplete library
Pros of Autocomplete
- More actively maintained with recent updates
- Offers a wider range of customization options
- Better documentation and community support
Cons of Autocomplete
- Steeper learning curve for beginners
- Requires more setup for basic functionality
- Larger file size, which may impact performance
Code Comparison
Typeahead.js:
$('#search-input').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: substringMatcher(states)
});
Autocomplete:
autocomplete({
container: '#search-input',
getSources({ query }) {
return [{
sourceId: 'products',
getItems() {
return getAlgoliaResults({
searchClient,
queries: [{ indexName: 'products', query }],
});
},
}];
},
});
Both libraries provide autocomplete functionality, but Autocomplete offers more flexibility and integration with Algolia's search services. Typeahead.js is simpler to set up for basic use cases, while Autocomplete provides more advanced features and customization options. The choice between the two depends on the specific requirements of your project and the level of complexity you're comfortable with.
Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
Pros of jQuery-Autocomplete
- Lightweight and easy to integrate with existing jQuery projects
- Supports custom data formatting and multiple data sources
- Offers more customization options for appearance and behavior
Cons of jQuery-Autocomplete
- Requires jQuery as a dependency, which may increase overall page load time
- Less robust handling of large datasets compared to typeahead.js
- Limited built-in features for advanced use cases
Code Comparison
jQuery-Autocomplete
$('#autocomplete').autocomplete({
serviceUrl: '/api/search',
onSelect: function(suggestion) {
console.log('Selected: ' + suggestion.value);
}
});
typeahead.js
$('#typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: substringMatcher(states)
});
Both libraries offer simple integration for basic autocomplete functionality. typeahead.js provides more built-in features like highlighting and hinting, while jQuery-Autocomplete focuses on flexibility and customization.
jQuery-Autocomplete is better suited for projects already using jQuery and requiring simple autocomplete functionality with easy customization. typeahead.js is more appropriate for larger applications needing advanced features and better performance with large datasets.
Ultra lightweight, usable, beautiful autocomplete with zero dependencies.
Pros of Awesomplete
- Lightweight and dependency-free (only 2KB minified and gzipped)
- Simple to use with minimal setup required
- Supports custom rendering of suggestions
Cons of Awesomplete
- Less feature-rich compared to Typeahead.js
- Limited customization options for advanced use cases
- Smaller community and fewer extensions/plugins available
Code Comparison
Awesomplete:
var input = document.getElementById("myinput");
new Awesomplete(input, {
list: ["Ada", "Java", "JavaScript", "Brainfuck", "LOLCODE", "Node.js", "Ruby on Rails"]
});
Typeahead.js:
$('#myinput').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'languages',
source: substringMatcher(["Ada", "Java", "JavaScript", "Brainfuck", "LOLCODE", "Node.js", "Ruby on Rails"])
});
Summary
Awesomplete is a lightweight, easy-to-use autocomplete library that's ideal for simple use cases and projects where minimal dependencies are preferred. It offers basic functionality with a straightforward setup process.
Typeahead.js, on the other hand, provides more advanced features and customization options, making it suitable for complex autocomplete requirements. It has a larger community and ecosystem but comes with a heavier footprint and jQuery dependency.
Choose Awesomplete for quick, simple implementations, and Typeahead.js for more robust, feature-rich autocomplete functionality.
Simple autocomplete pure vanilla Javascript library.
Pros of autoComplete.js
- Lightweight and dependency-free, making it easier to integrate into projects
- More modern and actively maintained, with regular updates and improvements
- Supports multiple data sources, including JSON, Arrays, and Functions
Cons of autoComplete.js
- Less extensive documentation compared to typeahead.js
- Fewer built-in features and customization options out of the box
- Smaller community and ecosystem, potentially leading to fewer resources and third-party extensions
Code Comparison
typeahead.js:
$('#search-input').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: substringMatcher(states)
});
autoComplete.js:
new autoComplete({
selector: "#search-input",
data: {
src: states,
cache: true,
},
resultsList: {
element: (list, data) => {
if (!data.results.length) {
const message = document.createElement("div");
message.setAttribute("class", "no_result");
message.innerHTML = `<span>Found No Results for "${data.query}"</span>`;
list.prepend(message);
}
},
noResults: true,
},
resultItem: {
highlight: true
}
});
Both libraries offer autocomplete functionality, but autoComplete.js provides a more modern API with additional features like custom result rendering and no-results handling. typeahead.js has a simpler setup but may require more configuration for advanced 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
typeahead.js
Inspired by twitter.com's autocomplete search functionality, typeahead.js is a flexible JavaScript library that provides a strong foundation for building robust typeaheads.
The typeahead.js library consists of 2 components: the suggestion engine, Bloodhound, and the UI view, Typeahead. The suggestion engine is responsible for computing suggestions for a given query. The UI view is responsible for rendering suggestions and handling DOM interactions. Both components can be used separately, but when used together, they can provide a rich typeahead experience.
Getting Started
How you acquire typeahead.js is up to you.
Preferred method:
- Install with Bower:
$ bower install typeahead.js
Other methods:
- Download zipball of latest release.
- Download the latest dist files individually:
- bloodhound.js (standalone suggestion engine)
- typeahead.jquery.js (standalone UI view)
- typeahead.bundle.js (bloodhound.js + typeahead.jquery.js)
- typeahead.bundle.min.js
Note: both bloodhound.js and typeahead.jquery.js have a dependency on jQuery 1.9+.
Documentation
Examples
For some working examples of typeahead.js, visit the examples page.
Browser Support
- Chrome
- Firefox 3.5+
- Safari 4+
- Internet Explorer 8+
- Opera 11+
NOTE: typeahead.js is not tested on mobile browsers.
Customer Support
For general questions about typeahead.js, tweet at @typeahead.
For technical questions, you should post a question on Stack Overflow and tag it with typeahead.js.
Issues
Discovered a bug? Please create an issue here on GitHub!
https://github.com/twitter/typeahead.js/issues
Versioning
For transparency and insight into our release cycle, releases will be numbered with the following format:
<major>.<minor>.<patch>
And constructed with the following guidelines:
- Breaking backwards compatibility bumps the major
- New additions without breaking backwards compatibility bumps the minor
- Bug fixes and misc changes bump the patch
For more information on semantic versioning, please visit http://semver.org/.
Testing
Tests are written using Jasmine and ran with Karma. To run
the test suite with PhantomJS, run $ npm test
.
Developers
If you plan on contributing to typeahead.js, be sure to read the contributing guidelines. A good starting place for new contributors are issues labeled with entry-level. Entry-level issues tend to require minor changes and provide developers a chance to get more familiar with typeahead.js before taking on more challenging work.
In order to build and test typeahead.js, you'll need to install its dev
dependencies ($ npm install
) and have grunt-cli
installed ($ npm install -g grunt-cli
). Below is an overview of the available
Grunt tasks that'll be useful in development.
grunt build
â Builds typeahead.js from source.grunt lint
â Runs source and test files through JSHint.grunt watch
â Rebuilds typeahead.js whenever a source file is modified.grunt server
â Serves files from the root of typeahead.js on localhost:8888. Useful for using test/playground.html for debugging/testing.grunt dev
â Runsgrunt watch
andgrunt server
in parallel.
Maintainers
-
Jake Harding
-
You?
Authors
-
Jake Harding
-
Veljko Skarich
-
Tim Trueman
License
Copyright 2013 Twitter, Inc.
Licensed under the MIT License
Top Related Projects
🔮 Fast and full-featured autocomplete library
Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
Ultra lightweight, usable, beautiful autocomplete with zero dependencies.
Simple autocomplete pure vanilla Javascript library.
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