Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
fix(autocomplete): Fixed not able to select autocomplete from dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianlee44 committed Sep 7, 2014
1 parent 4c49551 commit 609d14f
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/directives/autocomplete.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ angular.module("Mac").directive "macAutocomplete", [
# is selected in the menu
preventParser = false

# NOTE: preventBlur is used to prevent blur even from firing when user click
# on the menu
preventBlur = false

$menuScope = $scope.$new()
$menuScope.items = []
$menuScope.index = 0
Expand All @@ -131,20 +127,9 @@ angular.module("Mac").directive "macAutocomplete", [

reset()

$menuScope.onMousedown = ($event) ->
# prevent moving focus out of text field
$event.preventDefault()

preventBlur = true
$timeout ->
preventBlur = false
, 0, false


menuEl = angular.element(document.createElement("mac-menu"))
menuEl.attr
"ng-class": attrs.macMenuClass or null
"ng-mousedown": "onMousedown($event)"
"mac-menu-items": "items"
"mac-menu-select": "select(index)"
"mac-menu-index": "index"
Expand Down Expand Up @@ -181,10 +166,6 @@ angular.module("Mac").directive "macAutocomplete", [
the correct handler
###
blurHandler = ->
if preventBlur
preventBlur = false
return

$scope.$apply ->
reset()

Expand All @@ -199,6 +180,10 @@ angular.module("Mac").directive "macAutocomplete", [
unless isMenuAppended
element.bind "blur", blurHandler

# Bind mousedown event to prevent blur when clicking in menu
menuEl.on 'mousedown', (event) ->
event.preventDefault()

isMenuAppended = true

if inside
Expand Down

0 comments on commit 609d14f

Please sign in to comment.