Skip to content

Commit cf8c918

Browse files
committed
Activate ui-select only when user inputs 2+ chars in search box
This should help with performance, as per angular-ui/ui-select#88 (comment)
1 parent d125737 commit cf8c918

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/js/components/search-form.component.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class SearchFormCtrl {
33
'ngInject';
44

55
this._$state = $state;
6+
this.limitSeriesSearch = 0;
67

78
this.series = [
89
{ title: 'A Song of Ice and Fire', author: 'George RR Martin', keywords: 'Game of Thrones', slug:'a-song-of-ice-and-fire'},
@@ -11,6 +12,11 @@ class SearchFormCtrl {
1112
];
1213
};
1314

15+
// https://github.com/angular-ui/ui-select/issues/88#issuecomment-179916133
16+
checkSearch(search) {
17+
this.limitSeriesSearch = (search.length > 1)? 9999 : 0;
18+
}
19+
1420
submit() {
1521
if(this.selectedItem) {
1622
this._$state.go('app.graph', { slug: this.selectedItem.slug });

src/js/components/search-form.html

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<ng-transclude></ng-transclude>
2-
3-
<!-- classes ui-select-match & ui-select-choices required to fix https://github.com/angular-ui/ui-select/issues/1325 -->
4-
<ui-select ng-model="$ctrl.selectedItem" theme="bootstrap">
5-
<ui-select-match class="ui-select-match">
6-
<span ng-bind="$select.selected.title"></span>
7-
</ui-select-match>
8-
<ui-select-choices class="ui-select-choices" repeat="book in ($ctrl.series | filter: $select.search) track by book.slug">
9-
<span ng-bind="::book.title"></span>
10-
</ui-select-choices>
11-
</ui-select>
12-
<span class="input-group-btn">
13-
<button class="btn btn-s btn-primary pull-xs-right" type="submit"
14-
ng-class="{disabled: !$ctrl.selectedItem }"
15-
ng-click="$ctrl.submit()">Go!</button>
16-
</span>
2+
<div class="input-group">
3+
<!-- classes ui-select-match & ui-select-choices required to fix https://github.com/angular-ui/ui-select/issues/1325 -->
4+
<ui-select ng-model="$ctrl.selectedItem" reset-search-input="false">
5+
<ui-select-match class="ui-select-match" placeholder="Type your favourite sci-fi series or author...">
6+
<span ng-bind="$select.selected.title"></span>
7+
</ui-select-match>
8+
<ui-select-choices class="ui-select-choices" refresh="$ctrl.checkSearch($select.search)" refresh-delay="50"
9+
repeat="book in ($ctrl.series | filter: $select.search | limitTo: $ctrl.limitSeriesSearch) track by book.slug">
10+
<span ng-bind="book.title"></span>
11+
<small>by {{ book.author }}</small>
12+
</ui-select-choices>
13+
</ui-select>
14+
<span class="input-group-btn">
15+
<button class="btn btn-s btn-primary pull-xs-right" type="submit"
16+
ng-class="{disabled: !$ctrl.selectedItem }"
17+
ng-click="$ctrl.submit()">Go!</button>
18+
</span>
19+
</div>

0 commit comments

Comments
 (0)