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

fix(rating): fix usage of aria-valuetext #5573

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
4 changes: 3 additions & 1 deletion src/rating/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ angular.module('ui.bootstrap.rating', [])
})

.controller('UibRatingController', ['$scope', '$attrs', 'uibRatingConfig', function($scope, $attrs, ratingConfig) {
var ngModelCtrl = { $setViewValue: angular.noop };
var ngModelCtrl = { $setViewValue: angular.noop },
self = this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it really matters, but won't this.getTitle work in this situation, making self = this not needed?

Just like how this line works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually doesn't - I tried that first :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, do you know why that does not work? Just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is called in the render function, which is called in $scope.rate is my suspicion.


this.init = function(ngModelCtrl_) {
ngModelCtrl = ngModelCtrl_;
Expand Down Expand Up @@ -78,6 +79,7 @@ angular.module('ui.bootstrap.rating', [])

this.render = function() {
$scope.value = ngModelCtrl.$viewValue;
$scope.title = self.getTitle($scope.value - 1);
};
}])

Expand Down
1 change: 1 addition & 0 deletions src/rating/test/rating.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe('rating directive', function() {

expect(getState()).toEqual([true, true, false, false, false]);
expect(element.attr('aria-valuenow')).toBe('2');
expect(element.attr('aria-valuetext')).toBe('two');
});

it('shows different number of icons when `max` attribute is set', function() {
Expand Down
4 changes: 2 additions & 2 deletions template/rating/rating.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span ng-mouseleave="reset()" ng-keydown="onKeydown($event)" tabindex="0" role="slider" aria-valuemin="0" aria-valuemax="{{range.length}}" aria-valuenow="{{value}}">
<span ng-mouseleave="reset()" ng-keydown="onKeydown($event)" tabindex="0" role="slider" aria-valuemin="0" aria-valuemax="{{range.length}}" aria-valuenow="{{value}}" aria-valuetext="{{title}}">
<span ng-repeat-start="r in range track by $index" class="sr-only">({{ $index < value ? '*' : ' ' }})</span>
<i ng-repeat-end ng-mouseenter="enter($index + 1)" ng-click="rate($index + 1)" class="glyphicon" ng-class="$index < value && (r.stateOn || 'glyphicon-star') || (r.stateOff || 'glyphicon-star-empty')" ng-attr-title="{{r.title}}" aria-valuetext="{{r.title}}"></i>
<i ng-repeat-end ng-mouseenter="enter($index + 1)" ng-click="rate($index + 1)" class="glyphicon" ng-class="$index < value && (r.stateOn || 'glyphicon-star') || (r.stateOff || 'glyphicon-star-empty')" ng-attr-title="{{r.title}}"></i>
</span>