Skip to content

Commit 21cffe5

Browse files
committed
Don't hide select when SearchEnable is false
angular-ui#453 Update to move search box off screen Fix test to check against ui-select-offscreen class, not ng-hide Signed-off-by: Chris Jackson <[email protected]>
1 parent 7f30bcd commit 21cffe5

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

examples/bootstrap.html

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,35 @@
4242
<fieldset>
4343
<legend>ui-select inside a Bootstrap form</legend>
4444

45-
<div class="form-group">
46-
<label class="col-sm-3 control-label">Default</label>
47-
<div class="col-sm-6">
45+
<div class="form-group">
46+
<label class="col-sm-3 control-label">Default</label>
47+
<div class="col-sm-6">
48+
49+
<ui-select ng-model="person.selected" theme="bootstrap">
50+
<ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
51+
<ui-select-choices repeat="item in people | filter: $select.search">
52+
<div ng-bind-html="item.name | highlight: $select.search"></div>
53+
<small ng-bind-html="item.email | highlight: $select.search"></small>
54+
</ui-select-choices>
55+
</ui-select>
56+
57+
</div>
58+
</div>
4859

49-
<ui-select ng-model="person.selected" theme="bootstrap">
50-
<ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
51-
<ui-select-choices repeat="item in people | filter: $select.search">
52-
<div ng-bind-html="item.name | highlight: $select.search"></div>
53-
<small ng-bind-html="item.email | highlight: $select.search"></small>
54-
</ui-select-choices>
55-
</ui-select>
60+
<div class="form-group">
61+
<label class="col-sm-3 control-label">Search Disabled</label>
62+
<div class="col-sm-6">
5663

64+
<ui-select ng-model="person.selected" theme="bootstrap" search-enabled="false">
65+
<ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
66+
<ui-select-choices repeat="item in people | filter: $select.search">
67+
<div ng-bind-html="item.name | highlight: $select.search"></div>
68+
<small ng-bind-html="item.email | highlight: $select.search"></small>
69+
</ui-select-choices>
70+
</ui-select>
71+
72+
</div>
5773
</div>
58-
</div>
5974

6075
<div class="form-group">
6176
<label class="col-sm-3 control-label">Grouped</label>

src/bootstrap/match.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="ui-select-match" ng-hide="$select.open" ng-disabled="$select.disabled" ng-class="{'btn-default-focus':$select.focus}">
1+
<div class="ui-select-match" ng-hide="$select.searchEnabled && $select.open" ng-disabled="$select.disabled" ng-class="{'btn-default-focus':$select.focus}">
22
<span tabindex="-1"
33
class="btn btn-default form-control ui-select-toggle"
44
aria-label="{{ $select.baseTitle }} activate"

src/bootstrap/select.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
class="form-control ui-select-search"
99
placeholder="{{$select.placeholder}}"
1010
ng-model="$select.search"
11-
ng-show="$select.searchEnabled && $select.open">
11+
ng-show="$select.open">
1212
<div class="ui-select-choices"></div>
1313
</div>

src/uiSelectController.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ uis.controller('uiSelectCtrl',
113113
$scope.$broadcast('uis:activate');
114114

115115
ctrl.open = true;
116+
if(!ctrl.searchEnabled) {
117+
angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen');
118+
}
116119

117120
ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
118121

@@ -141,6 +144,10 @@ uis.controller('uiSelectCtrl',
141144
});
142145
}
143146
}
147+
else if (ctrl.open && !ctrl.searchEnabled) {
148+
// Close the selection if we don't have search enabled, and we click on the select again
149+
ctrl.close();
150+
}
144151
};
145152

146153
ctrl.focusSearchInput = function (initSearchValue) {
@@ -390,6 +397,9 @@ uis.controller('uiSelectCtrl',
390397
if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched();
391398
_resetSearchInput();
392399
ctrl.open = false;
400+
if(!ctrl.searchEnabled) {
401+
angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen');
402+
}
393403

394404
$scope.$broadcast('uis:close', skipFocusser);
395405

test/select.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,13 +1557,13 @@ describe('ui-select tests', function() {
15571557
it('should show search input when true', function() {
15581558
setupSelectComponent('true', 'bootstrap');
15591559
clickMatch(el);
1560-
expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide');
1560+
expect($(el).find('.ui-select-search')).not.toHaveClass('ui-select-offscreen');
15611561
});
15621562

15631563
it('should hide search input when false', function() {
15641564
setupSelectComponent('false', 'bootstrap');
15651565
clickMatch(el);
1566-
expect($(el).find('.ui-select-search')).toHaveClass('ng-hide');
1566+
expect($(el).find('.ui-select-search')).toHaveClass('ui-select-offscreen');
15671567
});
15681568

15691569
});

0 commit comments

Comments
 (0)