Skip to content

Commit b1cf051

Browse files
1 parent e1d8a3b commit b1cf051

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngc-omnibox",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"description": "A modern, flexible, Angular 1.x autocomplete library with limited assumptions.",
55
"main": "dist/ngc-omnibox.js",
66
"scripts": {

src/angularComponent/ngcOmniboxController.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ export default class NgcOmniboxController {
5656
$scope.$apply();
5757
}
5858

59+
// Focus/blur events are finicky, especially when the blur event fires when there's no other
60+
// focus target (such as hitting the ESC key, manually calling blur(), or on mobile when
61+
// hitting "Done" on the keyboard): the field can still be the focused element. This is a
62+
// problem since it means if the user then immediately tries to focus the field again, the
63+
// focus event won't fire (since technically the field is already focused). To combat this,
64+
// we check here to make absolutely certain that the field isn't currently focused and if it
65+
// is, we'll focus our main component element which a.) has a tabindex so we know it's
66+
// focuseable, and b.) allows us to keep listening for more events if we need to. Also,
67+
// since the element that kept focus is a child of our component element, focusing it won't
68+
// call the focus event listener again, avoiding an infinite loop.
69+
if (this.doc.activeElement === this.fieldElement) {
70+
this.element.focus();
71+
}
72+
5973
this.onBlur({event});
6074
}, SUGGESTIONS_BLUR_THRESHOLD);
6175
}, true);

0 commit comments

Comments
 (0)