An autocomplete/typeahead component for Vue 2 and Bootstrap 4

Overview

vue-bootstrap-typeahead

NPM

Build Status Coverage Status npm GitHub license

A simple list-group based typeahead/autocomplete using Bootstrap 4 and Vue 2

Preview image of the vue-bootstrap-typeahead component

View The Examples

Installation

From NPM:

> npm i vue-bootstrap-typeahead --save

Minified UMD and CommonJS builds are available in the 'dist' folder. The component is also available for use in the browser directly on unpkg:

<link href="https://unpkg.com/vue-bootstrap-typeahead/dist/VueBootstrapTypeahead.css" rel="stylesheet">
<script src="https://unpkg.com/vue-bootstrap-typeahead">script>

Usage

Import and register the component

import VueBootstrapTypeahead from 'vue-bootstrap-typeahead'

// Global registration
Vue.component('vue-bootstrap-typeahead', VueBootstrapTypeahead)

// OR

// Local registration
export default {
    components: {
        VueBootstrapTypeahead
    }
}

Basic Usage

The only required attribute is a data array.

<vue-bootstrap-typeahead 
  v-model="query"
  :data="['Canada', 'USA', 'Mexico']"
/>

Working with API's

The typeahead does not fetch any data, for maximum flexibility it will only work with already loaded API responses in the form of arrays. The serializer attribute allows you to define a function to turn each array item in the response into a text string, which will appear in the results.

<template>
  <vue-bootstrap-typeahead
    :data="addresses"
    v-model="addressSearch"
    size="lg"
    :serializer="s => s.text"
    placeholder="Type an address..."
    @hit="selectedAddress = $event"
  >
template>

<script>
import _ from 'underscore'

const API_URL = 'https://api-url-here.com?query=:query'

export default {
  name: 'TestComponent',

  data() {
    return {
      addresses: [],
      addressSearch: '',
      selectedAddress: null
    }
  },

  methods: {
    async getAddresses(query) {
      const res = await fetch(API_URL.replace(':query', query))
      const suggestions = await res.json()
      this.addresses = suggestions.suggestions
    }
  },

  watch: {
    addressSearch: _.debounce(function(addr) { this.getAddresses(addr) }, 500)
  }
}
script>

Attributes

Name Type Default Description
data Array Array of data to be available for querying. Required
serializer Function input => input Function used to convert the entries in the data array into a text string.
size String Size of the input-group. Valid values: sm or lg
backgroundVariant String Background color for the autocomplete result list-group items. See valid values
textVariant String Text color for the autocomplete result list-group items. See valid values
inputClass String Class to the added to the input tag for validation, etc.
maxMatches Number 10 Maximum amount of list items to appear.
minMatchingChars Number 2 Minimum matching characters in query before the typeahead list appears
prepend String Text to be prepended to the input-group
append String Text to be appended to the input-group

Events

Name Description
hit Triggered when an autocomplete item is selected. The entry in the input data array that was selected is returned.
input The component can be used with v-model

Slots

There are prepend and append slots available for adding buttons or other markup. Overrides the prepend and append attributes.

Scoped Slots

You can use a scoped slot called suggestion to define custom content for the suggestion list-item's

<vue-bootstrap-typeahead
  :data="countries"
  v-model="cntrySearch"
  :serializer="s => s.name"
  placeholder="Canada, United States, etc..."
  @hit="selectedCountry = $event"
>
  
  
  <template slot="suggestion" slot-scope="{ data, htmlText }">
    <span v-html="htmlText">span> <small>{{ data.code }}small>
  template>
vue-bootstrap-typeahead>

Local Examples/Demo

Clone this repository and run npm run serve and navigate to http://localhost:8080 to launch the documentation. The source is in src/views/Home.vue

You can also view and edit examples hosted on CodePen here

Contributing

Please note that active development is done on the Development branch. PR's are welcome!

Contributing

Please note that active development is done on the Development branch. PR's are welcome!

Sites using this component

  • plottr.io - Plan and map your running/cycling routes. This component is an offshoot from this project.

Send a pull request to add your site to this list!

Comments
  • SyntaxError: Unexpected token <

    SyntaxError: Unexpected token <

    I have added vue-bootstrap-typeahead to my project as follows:

    npm i vue-bootstrap-typeahead --save

    I have other components I am importing such as vue-bootstrap-datetimepicker like this:

    import DatePicker from 'vue-bootstrap-datetimepicker'

    However, when I try to import the vue-bootstrap-typeahead like this:

    import VueBootstrapTypeahead from 'vue-bootstrap-typeahead'

    I get the following error:

    SyntaxError: Unexpected token <

    I have also tried to use require but face the same error:

    var VueBootstrapTypeahead = require('vue-bootstrap-typeahead')

    I haven't even added it to my components or to my template

    Please advise why I might be having this issue.

    Thanks.

    opened by HasnatH 11
  • Keyboard navigation

    Keyboard navigation

    A previous pull request (#23) from @raymondmuller to add keyboard navigation failed merging due reduced unit test coverage, so I beefed it up where it was lacking.

    opened by FluencyMatt 6
  • Suggestion: Show complete list if minMatchingChars = 0

    Suggestion: Show complete list if minMatchingChars = 0

    Hello,

    First of all, thank you for this component! It would be nice if we could see the complete list (or the maxMatches if != 0) when the input gets the focus and minMatchingChars = 0.

    Thanks for your feedback!

    opened by Meshz 5
  • Results on top?

    Results on top?

    Is there a way to make the results appear above the searchfield? I fiddled around and manage to set margin-top: -120px; to the class .vbt-autcomplete-list[data-v-9a21a6f4].

    But how do I bind it? I have multiple searchfields on the same page and I would like this to only be set on one autocomplete-list.

    opened by dunderrrrrr 3
  • How it will work with typescript?

    How it will work with typescript?

    Not working with typescript, I'm getting error Error: Cannot find module 'vue-bootstrap-typeahead'. It's asking for dev dependency '@types/vue-bootstrap-typeahead'.

    opened by MKBLR23 2
  • maxMatches isn't passed to VueBootstrapTypeheadList

    maxMatches isn't passed to VueBootstrapTypeheadList

    maxMatches never propagates the value to the subcomponent VueBoostrapTypeheadList causing it to not update by overriding at the the VueBoostrapTypehead component level

    opened by jimfisher 2
  • Error in render when v-model is null

    Error in render when v-model is null

    Hello,

    Several errors are showing up when the v-model of the component is equal to null. For now I can avoid this value but I thought you should be aware of.

    [Vue warn]: Error in render: "TypeError: Cannot read property 'length' of null" found in <VueBootstrapTypeaheadList> at vue-bootstrap-typeahead/src/components/VueBootstrapTypeaheadList.vue TypeError: Cannot read property 'length' of null at VueComponent.matchedItems [Vue warn]: Error in mounted hook: "TypeError: Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element'." found in <VueBootstrapTypehead> at vue-bootstrap-typeahead/src/components/VueBootstrapTypeahead.vue TypeError: Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element' at VueComponent.mounted Uncaught TypeError: Cannot set property 'width' of undefined at VueComponent.resizeList

    opened by Meshz 2
  • #50-issue - Added a rawResults flag to VueBootstrapTypehead that enab…

    #50-issue - Added a rawResults flag to VueBootstrapTypehead that enab…

    Added a rawResults flag to VueBootstrapTypehead that enables it to show all the data results without filters in TypeheadList. Actually I had the same issue as mentioned here: https://github.com/alexurquhart/vue-bootstrap-typeahead/issues/50 . I have a data from server, that is already processed and filtered as I need. So this will help me or somebody else to do the same thing - just show all the data in TypeheadList if they've already processed it by adding a flag rawResults to their component. Like this: <vue-bootstrap-typeahead :data="countries" v-model="cntrySearch" :serializer="s => s.name" placeholder="Canada, United States, etc..." @hit="handleHit" :rawResults="true" /> Without the flag or setting it to false will act as it is now. P.S: I'm not really experienced contributor, so contact me please if I did something wrong and I'll be happy to fix myself up).

    opened by Yorikup 1
  • maxMatches not being respected?

    maxMatches not being respected?

    I am using version 0.26 and using the component as such:

    <vue-bootstrap-typeahead v-model="sampleOrderSKU1" :data="skuAutoCompleteData" :maxMatches="25" placeholder="SKU number"

    However, only 10 results are being displayed.

    opened by Lovecannon 1
  • Add suggestion scoped slot

    Add suggestion scoped slot

    #5

    • replaced the v-html on the list-item components with a prop, to be able to pass it to the scoped slot
    • added a data prop on the list-item component for the scoped slot too
    • added the scoped slot pass down on the main component + list component, however it's not perfect (see code comment) It would be way easier with this vuejs PR: https://github.com/vuejs/vue/pull/7765 Instead I had to do it manually, and met another issue (see https://github.com/vuejs/vue/issues/8305#issuecomment-417870543)
    • added an example in the demo
    opened by Owumaro 1
  • Slot for suggestion formatting

    Slot for suggestion formatting

    First of all, thanks for this plugin. I tried pretty much every other "vue-autocomplete" plugin and didn't find any as clean and customizable as this one. :+1:

    I'm trying to replace "seamlessly" google maps autocomplete with this plugin, therefore I need to achieve this UI:

    image

    As you can see the template is something like:

    <font-awesome-icon icon="map-marker-alt" /> {{ suggestion.name }} <small>{{ suggestion.countryName }}</small>
    

    However formatting is only customisable by the serializer property which requires a function.

    It would be nice to be able to use a scoped slot (see vue scoped slots).

    I will try to submit a PR when I have time.

    enhancement 
    opened by Owumaro 1
  • Bump node-sass from 4.9.3 to 7.0.0

    Bump node-sass from 4.9.3 to 7.0.0

    Bumps node-sass from 4.9.3 to 7.0.0.

    Release notes

    Sourced from node-sass's releases.

    v7.0.0

    Breaking changes

    Features

    Dependencies

    Community

    • Remove double word "support" from documentation (@​pzrq, #3159)

    Misc

    Supported Environments

    OS Architecture Node
    Windows x86 & x64 12, 14, 16, 17
    OSX x64 12, 14, 16, 17
    Linux* x64 12, 14, 16, 17
    Alpine Linux x64 12, 14, 16, 17
    FreeBSD i386 amd64 12, 14

    *Linux support refers to major distributions like Ubuntu, and Debian

    v6.0.1

    Dependencies

    Misc

    Supported Environments

    ... (truncated)

    Changelog

    Sourced from node-sass's changelog.

    v4.14.0

    https://github.com/sass/node-sass/releases/tag/v4.14.0

    v4.13.1

    https://github.com/sass/node-sass/releases/tag/v4.13.1

    v4.13.0

    https://github.com/sass/node-sass/releases/tag/v4.13.0

    v4.12.0

    https://github.com/sass/node-sass/releases/tag/v4.12.0

    v4.11.0

    https://github.com/sass/node-sass/releases/tag/v4.11.0

    v4.10.0

    https://github.com/sass/node-sass/releases/tag/v4.10.0

    v4.9.4

    https://github.com/sass/node-sass/releases/tag/v4.9.4

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Error When I try to use Number in Search

    Error When I try to use Number in Search

    I have to develop functionality that search zipcode from list of zipcode. When I try to search via city name or any field which string then its working fine. When I try to search with zipcode it cause error like in attached screenshot.

    Any help really Appreciated Screenshot_139 Screenshot_140

    opened by nadeem706 0
  • Use keyboard arrow up/down to move through candidate and Enter to select

    Use keyboard arrow up/down to move through candidate and Enter to select

    This is mostly a great component!

    However, it doesn't seem to support keyboard manipulation of candidate items, can you add arrow up/down and Enter to select? thanks.

    opened by yangzh 0
  • Typo error

    Typo error

    https://github.com/alexurquhart/vue-bootstrap-typeahead/blob/d0bc7650fbf5e907e5a9495c4f6794b267c2dcf3/src/components/VueBootstrapTypeahead.vue#L28

    It should be vbt-autocomplete-list.

    opened by ansidev 0
  • Prop for auto-placement of items list

    Prop for auto-placement of items list

    When typeahead input is on bottom of page and user open typeahead hints, many of them are out of screen. This is my solution of this problem.

    When input is on first 50% of viewport height, list displays as always to the bottom but when input is on second 50% of viewport height, list goes above the input.

    Thank you for your involvement in open-source solutions and I'll be glad if you find my PR helpful.

    opened by blint96 1
Owner
Alex Urquhart
Geomatics Professional :earth_americas:
Alex Urquhart
A simple tags input with typeahead (autocomplete) built with Vue.js 2.

Vue Tags Input v4 Forked from voerro/vue-tagsinput A simple tags input with typeahead built with Vue.js 2. Installation via NPM npm i @seriouslag/vue-

Landon Gavin 1 Nov 6, 2021
A simple tags input with typeahead (autocomplete) built with Vue.js 2.

Voerro Vue Tags Input v2 A simple tags input with typeahead built with Vue.js 2. Live Demo Installation via NPM npm i @voerro/vue-tagsinput --save-dev

null 0 Jul 8, 2021
Autocomplete - Accessible autocomplete component for vanilla JavaScript and Vue

Autocomplete Accessible autocomplete component for vanilla JavaScript and Vue. Demo Take a look at the documentation page, and the Codepen examples. F

Muhamad Septian 0 Dec 3, 2019
A simple tag component with typeahead

v-tag-suggestion A simple tag component with typeahead ⌨️ Install via npm npm install vue-tag-suggestion Import and register where you want to use imp

Maheshkumar 39 Mar 26, 2022
A Vue Autocomplete component with accessibility and simplicity in mind.

VueCompleter A Vue Autocomplete component with accessibility and simplicity in mind. Installation npm install vue-completer or yarn add vue-completer

Tom Elliott 3 Nov 8, 2020
A better vim plugin for stylus, including proper and up-to-date syntax highligting, indentation and autocomplete

Vim Stylus Vim + Stylus = fast, effective and convenient CSS workflow! Features All HTML5 tags and CSS3 props are covered Correct highlighting for int

Ilia Loginov 48 Dec 28, 2022
Autocomplete component for Vue.js

v-autocomplete Autocomplete component for Vue.js This component is css-free. The idea is to be used with any framework. Installation Using yarn yarn a

Marcos 347 Jan 3, 2023
Autocomplete component for Vue js

vuejs-auto-complete A Vue autocomplete component npm install vuejs-auto-complete --save Usage Installation, add autocomplete component into your app i

Charlie Kassel 136 Nov 8, 2022
Feature-rich autocomplete component for Vue.js

vue-simple-suggest Simple yet feature-rich autocomplete component for Vue.js Install npm install --save vue-simple-suggest See installation guide for

Marketplace Technologies 442 Jan 4, 2023
A Vue component for autocomplete email domains

vue-email-dropdown A Vue component for autocomplete email domains Features Allows passing a list of domains to be used in for the suggestions. Allows

Danny Feliz 27 Nov 24, 2022
Autocomplete Component for Vue.Js

vue-autocomplete Autocomplete Component for Vue.Js Intro Vue Autocomplete is a Vue.Js component to make some suggestions for user input. come with .vu

Naufal Rabbani 210 Jan 18, 2022
Vue 2 Component to make Autocomplete element.

Vue 2 Autocomplete Autocomplete component for Vue 2. This is a fork of vue2-autocomplete - Naufal Rabbani [email protected] Install You can imp

Eduardo Aguad 0 Oct 12, 2017
vue autoComplete component

vueto-complete vue autoComplete component Index Features Installation Examples Props Slots Events Styling LICENSE Features Supports full control over

Ahmed Abdallah 16 Jan 10, 2022
Google Autocomplete Vue Componet

Google Autocomplete I am sharing this component because I was overwhelmed by complicated examples to achieve this simple job. So, I will try to be as

Gustavo Ocanto 275 Aug 29, 2022
🧱 Very Downshift like autocomplete solution for Vue

Vue Combo Blocks ?? Provides all the building blocks needed for accessible autocomplete, combobox, or typeahead component. A very Downshift like autoc

Simeon Kerkola 17 Jul 7, 2022
🔍 Vue autosuggest component.

vue-autosuggest ?? Autosuggest component built for Vue. Table of Contents Examples Features Installation Usage Props Inspiration Contributors LICENSE

Darren Jennings 599 Dec 31, 2022
A configurable & lightweight Vue wrapper component that enables

A configurable & lightweight Vue wrapper component that enables "out of the box" email autocomplete/suggestions on input elements.

James Wylie 28 Jul 19, 2022
Mention component for Vue.js

vue-mention Mention popper for input and textarea Documentation Sponsors Quick start <script> import { Mentionable } from 'vue-mention' const users =

Guillaume Chau 462 Dec 22, 2022
🔍 Autosuggest component built for Vue

vue-autosuggest ?? Autosuggest component built for Vue. Table of Contents Examples Features Installation Usage Props Inspiration Contributors LICENSE

Алексей Мышкин 0 Dec 12, 2019