File tree 5 files changed +40
-15
lines changed 5 files changed +40
-15
lines changed Original file line number Diff line number Diff line change 42
42
< fieldset >
43
43
< legend > ui-select inside a Bootstrap form</ legend >
44
44
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 >
48
59
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 ">
56
63
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 >
57
73
</ div >
58
- </ div >
59
74
60
75
< div class ="form-group ">
61
76
< label class ="col-sm-3 control-label "> Grouped</ label >
Original file line number Diff line number Diff line change 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} ">
2
2
< span tabindex ="-1 "
3
3
class ="btn btn-default form-control ui-select-toggle "
4
4
aria-label ="{{ $select.baseTitle }} activate "
Original file line number Diff line number Diff line change 8
8
class ="form-control ui-select-search "
9
9
placeholder ="{{$select.placeholder}} "
10
10
ng-model ="$select.search "
11
- ng-show ="$select.searchEnabled && $select. open ">
11
+ ng-show ="$select.open ">
12
12
< div class ="ui-select-choices "> </ div >
13
13
</ div >
Original file line number Diff line number Diff line change @@ -113,6 +113,9 @@ uis.controller('uiSelectCtrl',
113
113
$scope . $broadcast ( 'uis:activate' ) ;
114
114
115
115
ctrl . open = true ;
116
+ if ( ! ctrl . searchEnabled ) {
117
+ angular . element ( ctrl . searchInput [ 0 ] ) . addClass ( 'ui-select-offscreen' ) ;
118
+ }
116
119
117
120
ctrl . activeIndex = ctrl . activeIndex >= ctrl . items . length ? 0 : ctrl . activeIndex ;
118
121
@@ -141,6 +144,10 @@ uis.controller('uiSelectCtrl',
141
144
} ) ;
142
145
}
143
146
}
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
+ }
144
151
} ;
145
152
146
153
ctrl . focusSearchInput = function ( initSearchValue ) {
@@ -390,6 +397,9 @@ uis.controller('uiSelectCtrl',
390
397
if ( ctrl . ngModel && ctrl . ngModel . $setTouched ) ctrl . ngModel . $setTouched ( ) ;
391
398
_resetSearchInput ( ) ;
392
399
ctrl . open = false ;
400
+ if ( ! ctrl . searchEnabled ) {
401
+ angular . element ( ctrl . searchInput [ 0 ] ) . removeClass ( 'ui-select-offscreen' ) ;
402
+ }
393
403
394
404
$scope . $broadcast ( 'uis:close' , skipFocusser ) ;
395
405
Original file line number Diff line number Diff line change @@ -1557,13 +1557,13 @@ describe('ui-select tests', function() {
1557
1557
it ( 'should show search input when true' , function ( ) {
1558
1558
setupSelectComponent ( 'true' , 'bootstrap' ) ;
1559
1559
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 ' ) ;
1561
1561
} ) ;
1562
1562
1563
1563
it ( 'should hide search input when false' , function ( ) {
1564
1564
setupSelectComponent ( 'false' , 'bootstrap' ) ;
1565
1565
clickMatch ( el ) ;
1566
- expect ( $ ( el ) . find ( '.ui-select-search' ) ) . toHaveClass ( 'ng-hide ' ) ;
1566
+ expect ( $ ( el ) . find ( '.ui-select-search' ) ) . toHaveClass ( 'ui-select-offscreen ' ) ;
1567
1567
} ) ;
1568
1568
1569
1569
} ) ;
You can’t perform that action at this time.
0 commit comments