Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

fix(rating): Set rating to 0 when viewValue is same as click value. #3963

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/rating/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ angular.module('ui.bootstrap.rating', [])

$scope.rate = function(value) {
if ( !$scope.readonly && value >= 0 && value <= $scope.range.length ) {
ngModelCtrl.$setViewValue(value);
ngModelCtrl.$setViewValue(ngModelCtrl.$viewValue === value ? 0 : value);
ngModelCtrl.$render();
}
};
Expand Down
6 changes: 6 additions & 0 deletions src/rating/test/rating.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ describe('rating directive', function () {
expect(getState()).toEqual([true, true, true, true, true]);
expect($rootScope.rate).toBe(5);
expect(element.attr('aria-valuenow')).toBe('5');

getStar(5).click();
$rootScope.$digest();
expect(getState()).toEqual([false, false, false, false, false]);
expect($rootScope.rate).toBe(0);
expect(element.attr('aria-valuenow')).toBe('0');
});

it('handles correctly the hover event', function() {
Expand Down