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

Commit 59d1d18

Browse files
committed
fix bug in arrow navigation
1 parent 5fa3482 commit 59d1d18

File tree

6 files changed

+33
-30
lines changed

6 files changed

+33
-30
lines changed

examples/bootstrap.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
<ui-select ng-model="person.selected" theme="bootstrap">
6565
<ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
66-
<ui-select-choices group-by="'age'" repeat="item in people | filter: $select.search">
66+
<ui-select-choices group-by="'group'" repeat="item in people | filter: $select.search">
6767
<span ng-bind-html="item.name | highlight: $select.search"></span>
6868
<small ng-bind-html="item.email | highlight: $select.search"></small>
6969
</ui-select-choices>

examples/demo.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ app.controller('DemoCtrl', function($scope, $http) {
5858

5959
$scope.person = {};
6060
$scope.people = [
61-
{ name: 'Adam', email: '[email protected]', age: 12 },
62-
{ name: 'Amalie', email: '[email protected]', age: 12 },
63-
{ name: 'Estefanía', email: 'estefaní[email protected]', age: 21 },
64-
{ name: 'Adrian', email: '[email protected]', age: 21 },
65-
{ name: 'Wladimir', email: '[email protected]', age: 30 },
66-
{ name: 'Samantha', email: '[email protected]', age: 30 },
67-
{ name: 'Nicole', email: '[email protected]', age: 43 },
68-
{ name: 'Natasha', email: '[email protected]', age: 54 }
61+
{ name: 'Adam', email: '[email protected]', group: 'Foo', age: 12 },
62+
{ name: 'Amalie', email: '[email protected]', group: 'Foo', age: 12 },
63+
{ name: 'Estefanía', email: 'estefaní[email protected]', group: 'Foo', age: 21 },
64+
{ name: 'Adrian', email: '[email protected]', group: 'Foo', age: 21 },
65+
{ name: 'Wladimir', email: '[email protected]', group: 'Foo', age: 30 },
66+
{ name: 'Samantha', email: '[email protected]', group: 'bar', age: 30 },
67+
{ name: 'Nicole', email: '[email protected]', group: 'bar', age: 43 },
68+
{ name: 'Natasha', email: '[email protected]', group: 'Baz', age: 54 }
6969
];
7070

7171
$scope.address = {};

examples/select2-bootstrap3.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
<ui-select ng-model="person.selected" theme="select2" class="form-control">
7272
<ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
73-
<ui-select-choices group-by="'age'" repeat="item in people | filter: $select.search">
73+
<ui-select-choices group-by="'group'" repeat="item in people | filter: $select.search">
7474
<span ng-bind-html="item.name | highlight: $select.search"></span>
7575
<small ng-bind-html="item.email | highlight: $select.search"></small>
7676
</ui-select-choices>

examples/selectize-bootstrap3.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
<ui-select ng-model="person.selected" theme="selectize">
8787
<ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
88-
<ui-select-choices group-by="'age'" repeat="item in people | filter: $select.search">
88+
<ui-select-choices group-by="'group'" repeat="item in people | filter: $select.search">
8989
<span ng-bind-html="item.name | highlight: $select.search"></span>
9090
<small ng-bind-html="item.email | highlight: $select.search"></small>
9191
</ui-select-choices>

src/select.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
};
9090

9191
self.getGroupNgRepeatExpression = function() {
92-
return '($group, $items) in $select.groups'
92+
return '($group, $items) in $select.groups';
9393
};
9494

9595
self.getNgRepeatExpression = function(lhs, rhs, trackByExp, grouped) {
@@ -170,7 +170,10 @@
170170
ctrl.groups[groupValue].push(item);
171171
}
172172
});
173-
setPlainItems(items);
173+
ctrl.items = [];
174+
angular.forEach(Object.keys(ctrl.groups).sort(), function(group) {
175+
ctrl.items = ctrl.items.concat(ctrl.groups[group]);
176+
});
174177
}
175178

176179
function setPlainItems(items) {
@@ -530,9 +533,9 @@
530533
var groupByExp = tAttrs.groupBy;
531534
return function link(scope, element, attrs, $select, transcludeFn) {
532535

533-
var groups = element.querySelectorAll('.ui-select-choices-group');
534536
if(groupByExp) {
535-
groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression())
537+
var groups = element.querySelectorAll('.ui-select-choices-group');
538+
groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression());
536539
}
537540

538541
var choices = element.querySelectorAll('.ui-select-choices-row');

test/select.spec.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ describe('ui-select tests', function() {
1414
};
1515

1616
scope.people = [
17-
{ name: 'Adam', email: '[email protected]', age: 12 },
18-
{ name: 'Amalie', email: '[email protected]', age: 12 },
19-
{ name: 'Estefanía', email: 'estefaní[email protected]', age: 21 },
20-
{ name: 'Adrian', email: '[email protected]', age: 21 },
21-
{ name: 'Wladimir', email: '[email protected]', age: 30 },
22-
{ name: 'Samantha', email: '[email protected]', age: 30 },
23-
{ name: 'Nicole', email: '[email protected]', age: 43 },
24-
{ name: 'Natasha', email: '[email protected]', age: 54 }
17+
{ name: 'Adam', email: '[email protected]', group: 'Foo', age: 12 },
18+
{ name: 'Amalie', email: '[email protected]', group: 'Foo', age: 12 },
19+
{ name: 'Estefanía', email: 'estefaní[email protected]', group: 'Foo', age: 21 },
20+
{ name: 'Adrian', email: '[email protected]', group: 'Foo', age: 21 },
21+
{ name: 'Wladimir', email: '[email protected]', group: 'Foo', age: 30 },
22+
{ name: 'Samantha', email: '[email protected]', group: 'bar', age: 30 },
23+
{ name: 'Nicole', email: '[email protected]', group: 'bar', age: 43 },
24+
{ name: 'Natasha', email: '[email protected]', group: 'Baz', age: 54 }
2525
];
2626
}));
2727

@@ -201,7 +201,7 @@ describe('ui-select tests', function() {
201201
return compileTemplate(
202202
'<ui-select ng-model="selection"> \
203203
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
204-
<ui-select-choices group-by="\'age\'" repeat="person in people | filter: $select.search"> \
204+
<ui-select-choices group-by="\'group\'" repeat="person in people | filter: $select.search"> \
205205
<div ng-bind-html="person.name | highlight: $select.search"></div> \
206206
<div ng-bind-html="person.email | highlight: $select.search"></div> \
207207
</ui-select-choices> \
@@ -211,14 +211,14 @@ describe('ui-select tests', function() {
211211

212212
it('should create items group', function() {
213213
var el = createUiSelect();
214-
expect(el.find('.ui-select-choices-group').length).toBe(5);
214+
expect(el.find('.ui-select-choices-group').length).toBe(3);
215215
});
216216

217217
it('should show label before each group', function() {
218218
var el = createUiSelect();
219219
expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function() {
220220
return this.textContent;
221-
}).toArray()).toEqual(['12', '21', '30', '43', '54']);
221+
}).toArray()).toEqual(['Baz', 'Foo', 'bar']);
222222
});
223223

224224
it('should hide empty groups', function() {
@@ -228,21 +228,21 @@ describe('ui-select tests', function() {
228228

229229
expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function() {
230230
return this.textContent;
231-
}).toArray()).toEqual(['12', '21', '30']);
231+
}).toArray()).toEqual(['Foo']);
232232
});
233233

234234
it('should change activeItem through groups', function() {
235235
var el = createUiSelect();
236-
el.scope().$select.search = 'd';
236+
el.scope().$select.search = 'n';
237237
scope.$digest();
238238
var choices = el.find('.ui-select-choices-row');
239239
expect(choices.eq(0)).toHaveClass('active');
240-
expect(getGroupLabel(choices.eq(0)).text()).toBe('12');
240+
expect(getGroupLabel(choices.eq(0)).text()).toBe('Baz');
241241

242242
triggerKeydown(el.find('input'), 40 /*Down*/);
243243
scope.$digest();
244244
expect(choices.eq(1)).toHaveClass('active');
245-
expect(getGroupLabel(choices.eq(1)).text()).toBe('21');
245+
expect(getGroupLabel(choices.eq(1)).text()).toBe('Foo');
246246
});
247247
});
248248

0 commit comments

Comments
 (0)