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

Commit dbceec7

Browse files
RopoMenwesleycho
authored andcommitted
fix(rating): Set rating to 0 when same value is selected
- When same rating value is selected, change rating value to 0 Closes #3963 Fixes #3246
1 parent 86bfec1 commit dbceec7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/rating/rating.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ angular.module('ui.bootstrap.rating', [])
3737

3838
$scope.rate = function(value) {
3939
if ( !$scope.readonly && value >= 0 && value <= $scope.range.length ) {
40-
ngModelCtrl.$setViewValue(value);
40+
ngModelCtrl.$setViewValue(ngModelCtrl.$viewValue === value ? 0 : value);
4141
ngModelCtrl.$render();
4242
}
4343
};

src/rating/test/rating.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ describe('rating directive', function () {
5555
expect(getState()).toEqual([true, true, true, true, true]);
5656
expect($rootScope.rate).toBe(5);
5757
expect(element.attr('aria-valuenow')).toBe('5');
58+
59+
getStar(5).click();
60+
$rootScope.$digest();
61+
expect(getState()).toEqual([false, false, false, false, false]);
62+
expect($rootScope.rate).toBe(0);
63+
expect(element.attr('aria-valuenow')).toBe('0');
5864
});
5965

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

0 commit comments

Comments
 (0)