3.1.0 • Published 9 months ago

vue3-bootstrap-autocomplete v3.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Nodejs workflow status

vue-bootstrap-autocomplete

A simple list-group based typeahead/autocomplete using Bootstrap 5 and Vue 3

Getting started

Installation

// npm
npm install vue3-bootstrap-autocomplete

// yarn
yarn add vue3-bootstrap-autocomplete

Registration

import VueBootstrapAutocomplete from 'vue3-bootstrap-autocomplete';

// Required dependency of bootstrap css/scss files
import 'bootstrap/scss/bootstrap.scss';

// Global registration
Vue.component('vue-bootstrap-autocomplete', VueBootstrapAutocomplete)

// or

// Local Registration
export default {
  components: {
    VueBootstrapAutocomplete
  }
}

Basic Usage

The only required props are a v-model and a data array.

<vue-bootstrap-autocomplete
  v-model="query"
  :data="['Canada', 'United States', 'Mexico', 'Netherlands']"
/>

Reference

Props

NametypeDefaultDescription
appendStringText to be appended to the input-group
autoCloseBooleantrueWhether the autocomplete should hide upon item selection
backgroundVariantStringBackground color for the autocomplete result list-group items. See values here.
backgroundVariantResolverFunctioninput => nullFunction which accepts the current list item data and returns a background color for the current autocomplete result list-group item. The non-null/non-empty string value returned from this function will supersede the value specified in backgroundVariant.
dataArrayArray of data to be available for querying. Required
disabledBooleanfalseEnable or disable input field
disabledValuesArrayfalseThe dropdown items to disable.
disableSortBooleanfalseIf set to true, no sorting occurs and the list is presented to the user as it is given to the component. Use this if you sort the list before giving it to the component. Ex: an elasticsearch result being passed to Vue.
highlightClassStringvbt-matched-textCSS class to style highlighted text
ieCloseFixBooleantrueAdds (imperfect) handling for auto closing the typeahead list on focus out in IE
inputClassStringClass to be added to the input tag for validation, etc.
inputNameStringName to be added to the input tag.
maxMatchesNumber10Maximum amount of list items to appear.
minMatchingCharsNumber2Minimum matching characters in query before the typeahead list appears
noResultsInfoStringNo results found.Text to display when no results are found
prependStringText to be prepended to the input-group
screenReaderTextSerializerFunctioninput => inputFunction used to convert the entries in the data array into the screen reader text string. Falls back to the value of serializer.
serializerFunctioninput => inputFunction used to convert the entries in the data array into a text string.
showAllResultsBooleanfalseShow all results even ones that highlighting doesn't match. This is useful when interacting with a API that returns results based on different values than what is displayed. Ex: user searches for "USA" and the service returns "United States of America".
showOnFocusBooleanfalseShow results as soon as the input gains focus before the user has typed anything.
sizeStringSize of the input-group. Valid values: sm, md, or lg
textVariantStringText color for autocomplete result list-group items. See values here.
stateBooleanWhether the autocomplete should be in a valid or invalid state.

Events

NameDescription
blurTriggered when the input field loses focus, except when pressing the tab key to focus the dropdown list.
focusTriggered when the input element receives focus.
hitTriggered when an autocomplete item is selected. The entry in the input data array that was selected is returned. If no autocomplete item is selected, the first entry matching the query is selected and returned.
inputThe component can be used with v-model
keyupTriggered when any keyup event is fired in the input. Often used for catching keyup.enter.
pasteTriggered when the user pastes text into the input field.

Slots

Prepend / Append

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

Example
<vue-bootstrap-autocomplete :data="data" v-model="value">
  <template #prepend>
    <button class="btn btn-primary">Prepend</button>
  </template>
  <template #append>
    <button class="btn btn-primary">Append</button>
  </template>
</vue-bootstrap-autocomplete>

No Results Info

There is a noResultsInfo slot available for customizing the no results info text. Overrides the noResultsInfo fallback content, which is undefined by default.

Example
<vue-bootstrap-autocomplete :data="data" v-model="query">
  <template #noResultsInfo>
    <span>No results for <b>{{ query }}</b></span>
  </template>
</vue-bootstrap-autocomplete>

Scoped Slot

You can use a scoped slot called suggestion to define custom content for the suggestion list-item's. You can use bound variables data, which holds the data from the input array, and htmlText, which is the highlighted text that is used for the suggestion.

See the custom suggestion slot example for more info.

3.1.0

9 months ago

3.0.3

9 months ago

3.0.2

9 months ago

3.0.1

9 months ago

3.0.0

9 months ago