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

Commit 2b093d7

Browse files
committed
fix(typeahead): select match on tab for iOS webview
- Select match on blur if only it has not been selected upon keydown fix(typeahead): move selected true logic to `select` method
1 parent 83c4266 commit 2b093d7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: src/typeahead/typeahead.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
7171

7272
var hasFocus;
7373

74+
//Used to avoid bug in iOS webview where iOS keyboard does not fire
75+
//mousedown & mouseup events
76+
//Issue #3699
77+
var selected;
78+
7479
//create a child scope for the typeahead directive so we are not polluting original scope
7580
//with typeahead-specific data (matches, query etc.)
7681
var scope = originalScope.$new();
@@ -255,6 +260,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
255260
var locals = {};
256261
var model, item;
257262

263+
selected = true;
258264
locals[parserResult.itemName] = item = scope.matches[activeIdx].model;
259265
model = parserResult.modelMapper(originalScope, locals);
260266
$setModelValue(originalScope, model);
@@ -283,7 +289,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
283289
}
284290

285291
// if there's nothing selected (i.e. focusFirst) and enter is hit, don't do anything
286-
if (scope.activeIdx == -1 && (evt.which === 13 || evt.which === 9)) {
292+
if (scope.activeIdx === -1 && (evt.which === 13 || evt.which === 9)) {
287293
return;
288294
}
289295

@@ -311,7 +317,14 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
311317
});
312318

313319
element.bind('blur', function (evt) {
320+
if (scope.matches.length && scope.activeIdx !== -1 && !selected) {
321+
selected = true;
322+
scope.$apply(function() {
323+
scope.select(scope.activeIdx);
324+
});
325+
}
314326
hasFocus = false;
327+
selected = false;
315328
});
316329

317330
// Keep reference to click handler to unbind it.

0 commit comments

Comments
 (0)