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

Commit 7900b41

Browse files
authored
Do not tag on blur if it is caused by clicking another element in select (#6)
1 parent d24c96e commit 7900b41

File tree

7 files changed

+24
-9
lines changed

7 files changed

+24
-9
lines changed

dist/select.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.6 - 2017-06-14T23:04:00.478Z
4+
* Version: 0.19.6 - 2017-06-17T00:07:08.500Z
55
* License: MIT
66
*/
77

dist/select.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.6 - 2017-06-14T23:04:00.285Z
4+
* Version: 0.19.6 - 2017-06-17T00:07:08.282Z
55
* License: MIT
66
*/
77

@@ -1028,7 +1028,9 @@ uis.controller('uiSelectCtrl',
10281028
});
10291029

10301030
// Allow tagging on blur
1031-
ctrl.searchInput.on('blur', function() {
1031+
ctrl.searchInput.on('blur', function($event) {
1032+
// do not tag on blur if focus is going to element within ui-select
1033+
if (ctrl.$element.has($event.relatedTarget).length) return;
10321034
if (ctrl.tagging.isActivated && ctrl.tagOnBlur) {
10331035
$timeout(function() {
10341036
ctrl.searchInput.triggerHandler('tagged');

dist/select.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uiSelectController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,9 @@ uis.controller('uiSelectCtrl',
748748
});
749749

750750
// Allow tagging on blur
751-
ctrl.searchInput.on('blur', function() {
751+
ctrl.searchInput.on('blur', function($event) {
752+
// do not tag on blur if focus is going to element within ui-select
753+
if (ctrl.$element.has($event.relatedTarget).length) return;
752754
if (ctrl.tagging.isActivated && ctrl.tagOnBlur) {
753755
$timeout(function() {
754756
ctrl.searchInput.triggerHandler('tagged');

test/select.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,6 +2922,17 @@ describe('ui-select tests', function() {
29222922
$timeout.flush();
29232923
expect(el.scope().$select.selected).toEqual(['tag,tag']);
29242924
});
2925+
2926+
it('should not tag on blur when blur event has related target', function () {
2927+
var el = createUiSelectMultiple({tagging: true, tagOnBlur: true});
2928+
setSearchText(el, 's');
2929+
openDropdown(el);
2930+
event = new jQuery.Event('blur');
2931+
event.relatedTarget = el.find('.ui-select-choices-row div:contains("Samantha")');
2932+
el.scope().$select.searchInput.trigger(event);
2933+
$timeout.flush();
2934+
expect(el.scope().$select.selected).toEqual([])
2935+
});
29252936
});
29262937

29272938
describe('resetSearchInput option multiple', function () {

0 commit comments

Comments
 (0)