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

Commit 86689b9

Browse files
committed
Merge pull request #668 from angular-ui/fix-focus-steal
fix(focus): prevent focus stealing when clicking on other ui-select element
2 parents 161a61f + f3bc359 commit 86689b9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/select.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,8 @@
11931193
};
11941194

11951195
function onDocumentClick(e) {
1196+
if (!$select.open) return; //Skip it if dropdown is close
1197+
11961198
var contains = false;
11971199

11981200
if (window.jQuery) {
@@ -1204,7 +1206,12 @@
12041206
}
12051207

12061208
if (!contains && !$select.clickTriggeredSelect) {
1207-
$select.close(angular.element(e.target).closest('.ui-select-container.open').length > 0); // Skip focusser if the target is another select
1209+
//Will lose focus only with certain targets
1210+
var focusableControls = ['input','button','textarea'];
1211+
var targetScope = angular.element(e.target).scope(); //To check if target is other ui-select
1212+
var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; //To check if target is other ui-select
1213+
if (!skipFocusser) skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); //Check if target is input, button or textarea
1214+
$select.close(skipFocusser);
12081215
scope.$digest();
12091216
}
12101217
$select.clickTriggeredSelect = false;

0 commit comments

Comments
 (0)