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

Commit

Permalink
fix(typeahead): select match on tab for iOS webview
Browse files Browse the repository at this point in the history
- Select match on blur if only it has not been selected upon keydown

Closes #3762
Fixes #3699
  • Loading branch information
wesleycho committed Jul 22, 2015
1 parent 7d1c460 commit 5b37bb8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap

var hasFocus;

//Used to avoid bug in iOS webview where iOS keyboard does not fire
//mousedown & mouseup events
//Issue #3699
var selected;

//create a child scope for the typeahead directive so we are not polluting original scope
//with typeahead-specific data (matches, query etc.)
var scope = originalScope.$new();
Expand Down Expand Up @@ -304,6 +309,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
var locals = {};
var model, item;

selected = true;
locals[parserResult.itemName] = item = scope.matches[activeIdx].model;
model = parserResult.modelMapper(originalScope, locals);
$setModelValue(originalScope, model);
Expand Down Expand Up @@ -366,13 +372,15 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
}
});

element.bind('blur', function (evt) {
if (isSelectOnBlur && scope.activeIdx >= 0) {
element.bind('blur', function () {
if (isSelectOnBlur && scope.matches.length && scope.activeIdx !== -1 && !selected) {
selected = true;
scope.$apply(function () {
scope.select(scope.activeIdx);
});
}
hasFocus = false;
selected = false;
});

// Keep reference to click handler to unbind it.
Expand Down

0 comments on commit 5b37bb8

Please sign in to comment.