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

Commit f3bc359

Browse files
committed
fix(focus): prevent to focus stealing on focusable targets
1 parent f012815 commit f3bc359

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/select.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,8 @@
11801180
};
11811181

11821182
function onDocumentClick(e) {
1183+
if (!$select.open) return; //Skip it if dropdown is close
1184+
11831185
var contains = false;
11841186

11851187
if (window.jQuery) {
@@ -1191,8 +1193,12 @@
11911193
}
11921194

11931195
if (!contains && !$select.clickTriggeredSelect) {
1194-
var targetScope = angular.element(e.target).scope();
1195-
$select.close(targetScope && targetScope.$select && targetScope.$select !== $select); // Skip focusser if the target is another select
1196+
//Will lose focus only with certain targets
1197+
var focusableControls = ['input','button','textarea'];
1198+
var targetScope = angular.element(e.target).scope(); //To check if target is other ui-select
1199+
var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; //To check if target is other ui-select
1200+
if (!skipFocusser) skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); //Check if target is input, button or textarea
1201+
$select.close(skipFocusser);
11961202
scope.$digest();
11971203
}
11981204
$select.clickTriggeredSelect = false;

0 commit comments

Comments
 (0)