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

Commit be0d301

Browse files
user378230aaronroberson
authored andcommitted
Fix numerous issues with select enabled (#1717)
* fix(searchEnabled): maintain keyboard nagivation Fix issue where keyboard navigation was disabled when searchEnabled was set to false. Caused by hiding the input box which prevent key events from propagating to the directive. Resolved hiding the input offscreen when searchEnabled is false. Fixes #1059, fixes #917, fixes #589, fixes #375 Closes #1543, closes #1114, closes #1109 (supersedes all) * fix(selectize): show placeholder when search disabled Previously when searchEnabled was set to false, the placeholder would also be hidden on the selectize theme. This fix sets the search input to disabled rather then hidden when the searchEnabled attribute is set to false. Fixes #1145, fixes #949, fixes #691 * fix(searchEnabled): Prevent searching when disabled Previously, even when search-enabled was set to false, users could still type in text and filter the list. This made disabling the search feature pointless. This fix prevents text entry to the search input and thus disables filtering. Fixes #1658
1 parent 0abae0b commit be0d301

File tree

8 files changed

+78
-13
lines changed

8 files changed

+78
-13
lines changed

docs/examples/demo-disable-search.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ <h3>Bootstrap theme</h3>
2323
</small>
2424
</ui-select-choices>
2525
</ui-select>
26+
<hr />
27+
<p>Number Selected: {{ctrl.multipleDemo.selectedPeople.length}}</p>
28+
<ui-select multiple ng-model="ctrl.multipleDemo.selectedPeople" theme="bootstrap" search-enabled="ctrl.searchEnabled" ng-disabled="ctrl.disabled" style="min-width: 300px;" title="Choose a person">
29+
<ui-select-match placeholder="Select person...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match>
30+
<ui-select-choices repeat="person in ctrl.people | propsFilter: {name: $select.search, age: $select.search}">
31+
<div ng-bind-html="person.name | highlight: $select.search"></div>
32+
<small>
33+
email: {{person.email}}
34+
age: <span ng-bind-html="''+person.age | highlight: $select.search"></span>
35+
</small>
36+
</ui-select-choices>
37+
</ui-select>
2638

2739
<h3>Select2 theme</h3>
2840
<p>Selected: {{ctrl.person.selected}}</p>
@@ -36,7 +48,18 @@ <h3>Select2 theme</h3>
3648
</small>
3749
</ui-select-choices>
3850
</ui-select>
39-
51+
<hr />
52+
<p>Number Selected: {{ctrl.multipleDemo.selectedPeople.length}}</p>
53+
<ui-select multiple ng-model="ctrl.multipleDemo.selectedPeople" theme="select2" search-enabled="ctrl.searchEnabled" ng-disabled="ctrl.disabled" style="min-width: 300px;">
54+
<ui-select-match placeholder="Select person...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match>
55+
<ui-select-choices repeat="person in ctrl.people | propsFilter: {name: $select.search, age: $select.search}">
56+
<div ng-bind-html="person.name | highlight: $select.search"></div>
57+
<small>
58+
email: {{person.email}}
59+
age: <span ng-bind-html="''+person.age | highlight: $select.search"></span>
60+
</small>
61+
</ui-select-choices>
62+
</ui-select>
4063
<h3>Selectize theme</h3>
4164
<p>Selected: {{ctrl.country.selected}}</p>
4265
<ui-select ng-model="ctrl.country.selected" theme="selectize" search-enabled="ctrl.searchEnabled" ng-disabled="ctrl.disabled" style="width: 300px;">

src/bootstrap/select.tpl.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
aria-owns="ui-select-choices-{{ $select.generatedId }}"
77
aria-activedescendant="ui-select-choices-row-{{ $select.generatedId }}-{{ $select.activeIndex }}"
88
class="form-control ui-select-search"
9+
ng-class="{ 'ui-select-search-hidden' : !$select.searchEnabled }"
910
placeholder="{{$select.placeholder}}"
1011
ng-model="$select.search"
11-
ng-show="$select.searchEnabled && $select.open">
12+
ng-show="$select.open">
1213
<div class="ui-select-choices"></div>
1314
<div class="ui-select-no-choice"></div>
1415
</div>

src/common.css

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ body > .select2-container.open {
7474
border-bottom-color: #5897fb;
7575
}
7676

77+
.ui-select-container[theme="select2"] .ui-select-dropdown .ui-select-search-hidden,
78+
.ui-select-container[theme="select2"] .ui-select-dropdown .ui-select-search-hidden input{
79+
opacity: 0;
80+
height: 0;
81+
min-height: 0;
82+
padding: 0;
83+
margin: 0;
84+
border:0;
85+
}
86+
7787
/* Selectize theme */
7888

7989
/* Helper class to show styles when focus */
@@ -99,10 +109,19 @@ body > .select2-container.open {
99109
/* Handle up direction Selectize */
100110
.ui-select-container[theme="selectize"].direction-up .ui-select-dropdown {
101111
box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25);
102-
103112
margin-top: -2px; /* FIXME hardcoded value :-/ */
104113
}
105114

115+
.ui-select-container[theme="selectize"] input.ui-select-search-hidden{
116+
opacity: 0;
117+
height: 0;
118+
min-height: 0;
119+
padding: 0;
120+
margin: 0;
121+
border:0;
122+
width: 0;
123+
}
124+
106125
/* Bootstrap theme */
107126

108127
/* Helper class to show styles when focus */
@@ -145,6 +164,15 @@ body > .select2-container.open {
145164
border-bottom-right-radius: 0 !important;
146165
}
147166

167+
.ui-select-bootstrap .ui-select-search-hidden{
168+
opacity: 0;
169+
height: 0;
170+
min-height: 0;
171+
padding: 0;
172+
margin: 0;
173+
border:0;
174+
}
175+
148176
.ui-select-bootstrap > .ui-select-match > .btn{
149177
/* Instead of center because of .btn */
150178
text-align: left !important;

src/select2/select.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="ui-select-match"></div>
77
<div class="ui-select-dropdown select2-drop select2-with-searchbox select2-drop-active"
88
ng-class="{'select2-display-none': !$select.open}">
9-
<div class="select2-search" ng-show="$select.searchEnabled">
9+
<div class="search-container" ng-class="{'ui-select-search-hidden':!$select.searchEnabled, 'select2-search':$select.searchEnabled}">
1010
<input type="search" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
1111
role="combobox"
1212
aria-expanded="true"

src/selectize/match.tpl.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
<div ng-hide="$select.searchEnabled && ($select.open || $select.isEmpty())" class="ui-select-match" ng-transclude></div>
1+
<div ng-hide="$select.searchEnabled && ($select.open || $select.isEmpty())" class="ui-select-match">
2+
<span ng-show="!$select.searchEnabled && ($select.isEmpty() || $select.open)" class="ui-select-placeholder text-muted">{{$select.placeholder}}</span>
3+
<span ng-hide="$select.isEmpty() || $select.open" ng-transclude></span>
4+
</div>
5+
6+

src/selectize/select.tpl.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
<div class="ui-select-match"></div>
66
<input type="search" autocomplete="off" tabindex="-1"
77
class="ui-select-search ui-select-toggle"
8+
ng-class="{'ui-select-search-hidden':!$select.searchEnabled}"
89
ng-click="$select.toggle($event)"
910
placeholder="{{$select.placeholder}}"
1011
ng-model="$select.search"
11-
ng-hide="!$select.searchEnabled || (!$select.isEmpty() && !$select.open)"
12+
ng-hide="!$select.isEmpty() && !$select.open"
1213
ng-disabled="$select.disabled"
1314
aria-label="{{ $select.baseTitle }}">
1415
</div>

src/uiSelectController.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ uis.controller('uiSelectCtrl',
156156
});
157157
}
158158
}
159+
else if (ctrl.open && !ctrl.searchEnabled) {
160+
// Close the selection if we don't have search enabled, and we click on the select again
161+
ctrl.close();
162+
}
159163
};
160164

161165
ctrl.focusSearchInput = function (initSearchValue) {
@@ -611,7 +615,10 @@ uis.controller('uiSelectCtrl',
611615
var tagged = false;
612616

613617
if (ctrl.items.length > 0 || ctrl.tagging.isActivated) {
614-
_handleDropDownSelection(key);
618+
if(!_handleDropDownSelection(key) && !ctrl.searchEnabled) {
619+
e.preventDefault();
620+
e.stopPropagation();
621+
}
615622
if ( ctrl.taggingTokens.isActivated ) {
616623
for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) {
617624
if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) {

test/select.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,12 +1749,12 @@ describe('ui-select tests', function() {
17491749

17501750
it('should show search input when true', function() {
17511751
setupSelectComponent(true, 'selectize');
1752-
expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide');
1752+
expect($(el).find('.ui-select-search')).not.toHaveClass('ui-select-search-hidden');
17531753
});
17541754

17551755
it('should hide search input when false', function() {
17561756
setupSelectComponent(false, 'selectize');
1757-
expect($(el).find('.ui-select-search')).toHaveClass('ng-hide');
1757+
expect($(el).find('.ui-select-search')).toHaveClass('ui-select-search-hidden');
17581758
});
17591759

17601760
});
@@ -1763,12 +1763,12 @@ describe('ui-select tests', function() {
17631763

17641764
it('should show search input when true', function() {
17651765
setupSelectComponent('true', 'select2');
1766-
expect($(el).find('.select2-search')).not.toHaveClass('ng-hide');
1766+
expect($(el).find('.search-container')).not.toHaveClass('ui-select-search-hidden');
17671767
});
17681768

17691769
it('should hide search input when false', function() {
17701770
setupSelectComponent('false', 'select2');
1771-
expect($(el).find('.select2-search')).toHaveClass('ng-hide');
1771+
expect($(el).find('.search-container')).toHaveClass('ui-select-search-hidden');
17721772
});
17731773

17741774
});
@@ -1778,13 +1778,13 @@ describe('ui-select tests', function() {
17781778
it('should show search input when true', function() {
17791779
setupSelectComponent('true', 'bootstrap');
17801780
clickMatch(el);
1781-
expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide');
1781+
expect($(el).find('.ui-select-search')).not.toHaveClass('ui-select-search-hidden');
17821782
});
17831783

17841784
it('should hide search input when false', function() {
17851785
setupSelectComponent('false', 'bootstrap');
17861786
clickMatch(el);
1787-
expect($(el).find('.ui-select-search')).toHaveClass('ng-hide');
1787+
expect($(el).find('.ui-select-search')).toHaveClass('ui-select-search-hidden');
17881788
});
17891789

17901790
});

0 commit comments

Comments
 (0)