vue autoComplete component

Overview

vueto-complete

vue autoComplete component

Index

Features

  • Supports full control over functionality and display.
  • Supports regular lists as well as AJAX fetching.
  • Supports grouping of results.
  • Supports slots for custom rendering and formatters for custom formatting.
  • Supports full control over styling.
  • Supports full control over filtering and sorting results.
  • Supports multiple keys to search against.
  • Supports keyboard accessibility.
  • Fires events for all its lifesycle hooks.

Installation

npm install --save vueto-complete

or

yarn add vueto-complete

Examples

">
<template>
  <div>
    <VuetoComplete
        v-model="query"
        :auto-complete-list="list"
        :styles="styles"
    >
    VuetoComplete>
  div>
template>

<script>
  import VuetoComplete from 'vueto-complete';
  
  const styles = {
    container: {
      maxWidth: '500px',
    },
    input: {
      border: '1px solid gray',
    },
    focusedInput: {
      background: '#e0e0e0',
    },
  };
  
  export default {
    name: 'app',
    data: () => ({
      query: '',
      styles,
      list: [
        'Cairo, Egypt',
        'Cairo, Thomasville, United States',
        'Cairo, Southwest Illinois, United States',
        'Giza, Cairo, Egypt',
        'Cairo, Central West Virginia, United States',
        'Cairo Montenotte, Savona - Riviera Delle Palme, Italy',
      ],
    }),
    components: {
      VuetoComplete,
    }
  };
script>
">
<template>
  <div>
    <VuetoComplete
        :fetch-handler="getTodos"
        display-key="title"
        :filter-handler="getCompleted"
        @select="onSelect"
    >
    VuetoComplete>
  div>
template>

<script>
  import VuetoComplete from 'vueto-complete';
  
  export default {
    name: 'app',
    methods: {
      /**
       * get todos
       *
       * @param {String} query
       * @returns {Promise}
       */
      getTodos(query) {
        return fetch('https://jsonplaceholder.typicode.com/todos')
          .then(response => response.json());
      },
      
      /**
       * filter todos by completed
       * @param {Array} todos
       * @return {Array} todos
       */
      getCompleted(todos) {
        return todos.filter(({ completed }) => completed);
      },
  
      /**
       * handle select
       * @param {Object} todo
       */
      onSelect(todo) {
        console.log(todo);
      }
    },
    components: {
      VuetoComplete,
    },
  };
script>

">
<template>
  <div>
    <VuetoComplete
        :fetch-handler="getPosts"
        display-key="title"
        :search-keys="['title', 'body']"
        :debounce-time="200"
        :min-chars-to-auto-complete="2"
        :max-results-to-display="5"
        @select="onSelect"
    >
      <template slot="item-icon" slot-scope="{ item }">
        <i :class="`post-icon-${item.id}`">i>
      template>
    VuetoComplete>
  div>
template>

<script>
  import VuetoComplete from 'vueto-complete';
  
  export default {
    name: 'app',
    methods: {
      /**
       * get posts
       *
       * @param {String} query
       * @returns {Promise}
       */
      getPosts(query) {
        return fetch('https://jsonplaceholder.typicode.com/posts')
          .then(response => response.json());
      },
      
      /**
       * handle select
       * @param {Object} post
       */
      onSelect(post) {
        console.log(post);
      }
    },
    components: {
      VuetoComplete,
    },
  };
script>

Props

Prop Type Default Required Description
autoCompleteList Array empty array [ ] only when no fetchHandler provided autoCompleteList is required only if no fetchHandler provided, it can be array of strings or objects
fetchHandler Function no default only when no autoCompleteList provided fetchHandler for fetching AJAX results, it's a function returns a promise resolves to a list, it's required only if no autoCompleteList provided.
displayKey String title only when the results are a list of objects displayKey is the key that will be displayed in the list, it's required only if the list is array of objects and you can override how you display the results with resultsDisplayFormatHandler prop
searchKeys Array [displayKey] No you can provide multiple keys from the result object to search against while autoCompleting
sortHandler Function no default No a function to sort the autoCompleted results
filterHandler Function no default No a function to filter the autoCompleted results
resultsDisplayFormatHandler Function no default No a function to format how the results get displayed
selectedItemFormatHandler Function no default No a function to format how the selected result get displayed on the autoComplete input
minCharsToAutoComplete Number 1 No the minimum characters to start autoComplete or fetch
maxResultsToDisplay Number Infinity No the maximum results to display
debounceTime Number 300 ms No debounce time for the input event while fetching results
highlightMatched Boolean true No highlight matched words as the query
showLoadingIcon Boolean true No show loading icon while fetching results
fetchOnFocus Boolean false No fetch results with the current query on input focus
placeholder String empty string No autoComplete input placeholder
noResultsMessage Boolean No results found No the message to display when no results matches the current query
showNoResultsMessage String true No show a message when no results matches the current query
testId String empty string No id to define a data attribute data-test-id for each element in the component for automation test
emptyResultsOnEmptyQuery Boolean true No empty the results array when the input query get empty
highlightResults Boolean true No highlight results with hovering over it or using keyboard
useCategories Boolean false No categorise results
categoryKey String no default only when useCategories is true the key to categorise with
categoryLabel String no default No the label to show for the category, if it's not provided the categoryKey prop will be used as a label
initialValue String empty string ' ' No initial value for the input query
styles Object empty object { } No styles object to style each element in the component in all its states

Slots

Name Scope Description
input-icon no scope it renders icon for the input
input-label no scope it renders label for the input
item current item object it renders the result item
item-icon current item object it renders the result item icon
item-caption current item object it renders the result item caption
loading-icon no scope it renders the input loading icon
no-results no scope it renders the no results message

Events

Name Payload Description
input no payload fired on input change, you can use v-model on the component
startedFetching no payload fired before fetch start
fetchSuccess results list fired on fetch success
fetchError error fired on fetch error
finishedFetching no payload fired after fetch resolve/reject
select selected item object fired on selecting autoComplete item
inputFocus no payload fired on focusing the input
inputBlur no payload fired on bluring the input
highlightItem item index fired on highlighting new item with hover/keyboard
noResultsFound no payload fired on when no results found

Styling

Key description
container to style the component container
input to style the input
focusedInput to style the input in the focus state
inputWrapper to style the input wrapper
focusedInputWrapper to style the input wrapper in the focus state
inputLabel to style the input label
focusedInputLabel to style the input label in the focus state
resultsList to style the results list
resultItem to style the result item
highlightedItem to style the result item in the highlight state
matchedWords to style the matched words
highlightedMatchedWords to style the matched words in the highlight state
categoryLabel to style the category label

LICENSE

MIT

You might also like...
A simple tags input with typeahead (autocomplete) built with Vue.js 2.
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-

A simple tags input with typeahead (autocomplete) built with Vue.js 2.
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

A better vim plugin for stylus, including proper and up-to-date syntax highligting, indentation and autocomplete
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

๐Ÿ” Vue autosuggest component.
๐Ÿ” Vue autosuggest component.

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

A configurable & lightweight Vue wrapper component that enables
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.

Mention component for Vue.js
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 =

 ๐Ÿ” Autosuggest component built for Vue
๐Ÿ” Autosuggest component built for Vue

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

A simple modular Vuejs component that autosuggest input from a dyanamic or static data querying.
A simple modular Vuejs component that autosuggest input from a dyanamic or static data querying.

v-autosuggest A simple modular Vuejs component that autosuggest input from a dyanamic or static data querying. Table of contents Installation Usage Pr

A simple tag component with typeahead
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

Owner
Ahmed Abdallah
Senior Software Engineer @Shopify
Ahmed Abdallah
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
An autocomplete/typeahead component for Vue 2 and Bootstrap 4

vue-bootstrap-typeahead A simple list-group based typeahead/autocomplete using Bootstrap 4 and Vue 2 View The Examples Installation From NPM: > npm i

Alex Urquhart 209 Nov 19, 2022
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
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
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