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

feat(events): expose uis-open-close callback #1723

Merged
merged 1 commit into from
Jul 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/uisOpenCloseDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
uis.directive('uisOpenClose', ['$parse', '$timeout', function ($parse, $timeout) {
return {
restrict: 'A',
require: 'uiSelect',
link: function (scope, element, attrs, $select) {
$select.onOpenCloseCallback = $parse(attrs.uisOpenClose);

scope.$watch('$select.open', function (isOpen, previousState) {
if (isOpen !== previousState) {
$timeout(function () {
$select.onOpenCloseCallback(scope, {
isOpen: isOpen
});
});
}
});
}
};
}]);
26 changes: 26 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,32 @@ describe('ui-select tests', function() {
expect(scope.$model).toBe(scope.$item);
});

it('should call open-close callback with isOpen state as first argument on open and on close', function () {

var el = compileTemplate(
'<ui-select uis-open-close="onOpenCloseFn(isOpen)" ng-model="selection.selected"> \
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
<ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
<div ng-bind-html="person.name | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select>'
);

scope.onOpenCloseFn = function(){};
spyOn(scope, 'onOpenCloseFn');

openDropdown(el);
$timeout.flush();
expect(scope.onOpenCloseFn).toHaveBeenCalledWith(true);

closeDropdown(el);
$timeout.flush();
expect(scope.onOpenCloseFn).toHaveBeenCalledWith(false);

expect(scope.onOpenCloseFn.calls.count()).toBe(2);
});

it('should allow creating tag in single select mode with tagging enabled', function() {

scope.taggingFunc = function (name) {
Expand Down