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`.
focus | Triggered when the input element receives focus.
blur | Triggered when the input field loses focus, except when pressing the `tab` key to focus the dropdown list.

## Slots
Expand Down
9 changes: 8 additions & 1 deletion src/components/VueTypeaheadBootstrap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
:aria-label="(!ariaLabelledBy) ? placeholder : false"
:value="inputValue"
:disabled="disabled"
@focus="isFocused = true"
@focus="handleFocus"
@blur="handleFocusOut"
@input="handleInput($event.target.value)"
@keydown.esc="handleEsc($event.target.value)"
Expand Down Expand Up @@ -171,6 +171,8 @@ export default {
highlightClass: String
},

emits: ['hit', 'input', 'keyup', 'focus', 'blur'],

computed: {
id() {
return Math.floor(Math.random() * 100000)
Expand Down Expand Up @@ -257,6 +259,11 @@ export default {
}
},

handleFocus() {
this.$emit('focus')
this.isFocused = true
},

handleInput(newValue) {
this.isFocused = true
this.inputValue = newValue
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/VueTypeaheadBootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,11 @@ describe('VueTypeaheadBootstrap', () => {

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

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