Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/guide/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
| serializer | Function | `input => input`| Function used to convert the entries in the data array into a text string. |
| showAllResults | `Boolean` | false | Show 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".
| showOnFocus | `Boolean` | false | Show results as soon as the input gains focus before the user has typed anything.
| focusFirst | `Boolean` | true | Option to disable first item auto selection, so user can enter free search queries by setting false.
| size | String | | Size of the `input-group`. Valid values: `sm`, `md`, or `lg` |
| textVariant | String | | Text color for autocomplete result `list-group` items. [See values here.][2]

Expand Down
13 changes: 13 additions & 0 deletions src/components/VueTypeaheadBootstrap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
:highlightClass='highlightClass'
:disabledValues="disabledValues"
:vbtUniqueId="id"
:focusFirst="focusFirst"
role="listbox"

>
<!-- pass down all scoped slots -->
<template v-for="(slot, slotName) in $scopedSlots" :slot="slotName" slot-scope="{ data, htmlText }">
Expand Down Expand Up @@ -153,6 +155,10 @@ export default {
type: Boolean,
default: false
},
focusFirst: {
type: Boolean,
default: true
},
showAllResults: {
type: Boolean,
default: false
Expand Down Expand Up @@ -222,13 +228,15 @@ export default {
},

handleHit(evt) {

if (typeof this.value !== 'undefined') {
this.$emit('input', evt.text)
}

this.inputValue = evt.text
this.$emit('hit', evt.data)


if (this.autoClose) {
this.$refs.input.blur()
this.isFocused = false
Expand Down Expand Up @@ -264,9 +272,14 @@ export default {
if (typeof this.value !== 'undefined') {
this.$emit('input', newValue)
}
else{
this.$emit('input', "")
}
},

handleEsc(inputValue) {


if (inputValue === '') {
this.$refs.input.blur()
this.isFocused = false
Expand Down
14 changes: 12 additions & 2 deletions src/components/VueTypeaheadBootstrapList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export default {
type: Boolean,
default: false
},
focusFirst: {
type: Boolean,
default: true
},
highlightClass: {
type: String,
default: 'vbt-matched-text'
Expand Down Expand Up @@ -179,9 +183,13 @@ export default {
evt.preventDefault()
},
hitActiveListItem() {
if (this.activeListItem < 0) {
if(!this.focusFirst){
this.$emit('hit', "");
}
else if (this.activeListItem < 0) {
this.selectNextListItem();
}

if (this.activeListItem >= 0) {
this.$emit('hit', this.matchedItems[this.activeListItem])
}
Expand Down Expand Up @@ -227,7 +235,9 @@ export default {
return true
}

this.activeListItem = this.findIndexForNextActiveItem()
this.activeListItem = this.findIndexForNextActiveItem();


},

selectPreviousListItem() {
Expand Down