Skip to content

Commit 86c2ab0

Browse files
committed
Update to move search box off screen
1 parent 84f4a7c commit 86c2ab0

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
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/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
@@ -79,6 +79,9 @@ uis.controller('uiSelectCtrl',
7979
$scope.$broadcast('uis:activate');
8080

8181
ctrl.open = true;
82+
if(!ctrl.searchEnabled) {
83+
angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen');
84+
}
8285

8386
ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
8487

@@ -94,6 +97,10 @@ uis.controller('uiSelectCtrl',
9497
ctrl.searchInput[0].focus();
9598
});
9699
}
100+
else if (ctrl.open && !ctrl.searchEnabled) {
101+
// Close the selection if we don't have search enabled, and we click on the select again
102+
ctrl.close();
103+
}
97104
};
98105

99106
ctrl.findGroupByName = function(name) {
@@ -312,6 +319,9 @@ uis.controller('uiSelectCtrl',
312319
if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched();
313320
_resetSearchInput();
314321
ctrl.open = false;
322+
if(!ctrl.searchEnabled) {
323+
angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen');
324+
}
315325

316326
$scope.$broadcast('uis:close', skipFocusser);
317327

0 commit comments

Comments
 (0)