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

Commit 0762368

Browse files
committed
Merge pull request #320 from phxdatasec/feat-highlight
Adding ability to have a callback for highlighting an item
2 parents 3be92eb + 6fb7e74 commit 0762368

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/select.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,13 @@
305305
};
306306

307307
ctrl.isActive = function(itemScope) {
308-
return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
308+
var isActive = ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
309+
310+
if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) {
311+
itemScope.$eval(ctrl.onHighlightCallback);
312+
}
313+
314+
return isActive;
309315
};
310316

311317
ctrl.isDisabled = function(itemScope) {
@@ -888,6 +894,7 @@
888894
$select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult
889895

890896
$select.disableChoiceExpression = attrs.uiDisableChoice;
897+
$select.onHighlightCallback = attrs.onHighlight;
891898

892899
if(groupByExp) {
893900
var groups = element.querySelectorAll('.ui-select-choices-group');

test/select.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,35 @@ describe('ui-select tests', function() {
727727

728728
});
729729

730+
it('should invoke hover callback', function(){
731+
732+
var highlighted;
733+
scope.onHighlightFn = function ($item) {
734+
highlighted = $item;
735+
};
736+
737+
var el = compileTemplate(
738+
'<ui-select on-select="onSelectFn($item, $model)" ng-model="selection.selected"> \
739+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
740+
<ui-select-choices on-highlight="onHighlightFn(person)" repeat="person.name as person in people | filter: $select.search"> \
741+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
742+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
743+
</ui-select-choices> \
744+
</ui-select>'
745+
);
746+
747+
expect(highlighted).toBeFalsy();
748+
749+
if (!isDropdownOpened(el)){
750+
openDropdown(el);
751+
}
752+
753+
$(el).find('.ui-select-choices-row div:contains("Samantha")').trigger('mouseover');
754+
scope.$digest();
755+
756+
expect(highlighted).toBe(scope.people[5]);
757+
})
758+
730759
it('should set $item & $model correctly when invoking callback on select and no single prop. binding', function () {
731760

732761
scope.onSelectFn = function ($item, $model, $label) {

0 commit comments

Comments
 (0)