Skip to content
Merged
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 @@ -33,6 +33,7 @@ Name | Description
hit | Triggered 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.
input | The component can be used with `v-model`
keyup | Triggered when any keyup event is fired in the input. Often used for catching `keyup.enter`.
blur | Triggered when the input field loses focus, except when pressing the `tab` key to focus the dropdown list.

## Slots

Expand Down
9 changes: 5 additions & 4 deletions src/components/VueTypeaheadBootstrap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,20 @@ export default {
this.isFocused = false
},

runFocusOut(tgt) {
runFocusOut(evt) {
const tgt = evt.relatedTarget
if (tgt && tgt.classList.contains('vbst-item')) {
return
}
this.$emit('blur', evt)
this.isFocused = false
},

handleFocusOut(evt) {
const tgt = evt.relatedTarget
if (!!navigator.userAgent.match(/Trident.*rv:11\./) && this.ieCloseFix) {
setTimeout(() => { this.runFocusOut(tgt) }, 300)
setTimeout(() => { this.runFocusOut(evt) }, 300)
} else {
this.runFocusOut(tgt)
this.runFocusOut(evt)
}
},

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/VueTypeaheadBootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,22 @@ describe('VueTypeaheadBootstrap', () => {

expect(selectPreviousListItem).toHaveBeenCalledWith()
})

it('Emits a blur event when the underlying input field blurs', async () => {
let input = wrapper.find('input')
await input.trigger('blur')
expect(wrapper.emitted().blur).toBeTruthy()
})

it('Does not emit a blur event if the focus shifted to the dropdown list', async () => {
let input = wrapper.find('input')
wrapper.setData({ inputValue: 'Can' })
await input.trigger('focus')

let listItem = wrapper.get('.vbst-item').element
await input.trigger('blur', {relatedTarget: listItem})

expect(wrapper.emitted().blur).toBeFalsy()
})
})
})