Skip to content

Commit

Permalink
Fix for auto-first loosing focus on open being called
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed May 16, 2018
1 parent 66429f4 commit 1bc535a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
20 changes: 9 additions & 11 deletions module/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ export class Typeahead {
* Focus on the suggestion at the given index.
*/
focus(index) {

// Remove the focused CSS class any suggestion element in the type
// ahead.
const focusedCSS = this.constructor.css['focused']
Expand Down Expand Up @@ -413,7 +412,13 @@ export class Typeahead {
/**
* Open the typeahead.
*/
open() {
open() {
// If the `autoFirst` option is true and no suggestion currently has
// focus then select the first option.
if (this._options.autoFirst && this.index === -1) {
this.focus(0)
}

// If the typeahead is already open there's nothing to do
if (this.isOpen) {
return
Expand All @@ -433,12 +438,6 @@ export class Typeahead {
// Flag the typeahead as open
this._open = true

// If the `autoFirst` option is true and no suggestion currently has
// focus then select the first option.
if (this._options.autoFirst && this.index === -1) {
this.focus(0)
}

// Dispatch opened event against the input
$.dispatch(this.input, 'opened')
}
Expand Down Expand Up @@ -499,7 +498,6 @@ export class Typeahead {
$.dispatch(this.input, 'selected', {suggestion})
}


/**
* Update the typeahead to show relevant suggestions for the given query.
*/
Expand Down Expand Up @@ -576,10 +574,10 @@ export class Typeahead {
// suggestions and display the typeahead.
const element = behaviours.element[this._behaviours.element]
for (let suggestion of this._suggestions) {
this.typeahead.appendChild(element(this, suggestion, q))
let suggestionElm = element(this, suggestion, q)
this.typeahead.appendChild(suggestionElm)
}
this.open()

})
.catch((e) => {

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "manhattan-typeahead",
"version": "1.0.2",
"version": "1.0.3",
"version": "1.0.4",
"description": "Type-a-head and tokens for form fields.",
"engines": {
"node": ">=8.9.4"
Expand Down

0 comments on commit 1bc535a

Please sign in to comment.