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

Commit f2e8730

Browse files
committed
fix(carousel): disable prev/next arrows if noWrap and at bounds
1 parent cd90800 commit f2e8730

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Diff for: src/carousel/carousel.js

+8
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ angular.module('ui.bootstrap.carousel', [])
123123
return $scope.active === slide.slide.index;
124124
};
125125

126+
$scope.isPrevDisabled = function() {
127+
return $scope.active === 0 && $scope.noWrap();
128+
};
129+
130+
$scope.isNextDisabled = function() {
131+
return $scope.active === slides.length - 1 && $scope.noWrap();
132+
};
133+
126134
$scope.pause = function() {
127135
if (!$scope.noPause) {
128136
isPlaying = false;

Diff for: src/carousel/test/carousel.spec.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,20 @@ describe('carousel', function() {
163163
expect(navPrev.length).toBe(0);
164164
});
165165

166-
it('should not show prev button when slide index is 0 and noWrap is truthy', function() {
166+
it('should disable prev button when slide index is 0 and noWrap is truthy', function() {
167167
scope.$apply();
168168

169169
var $scope = elm.isolateScope();
170170
$scope.noWrap = function() {return true;};
171+
172+
$scope.isPrevDisabled();
171173
scope.$apply();
172174

173175
var navPrev = elm.find('a.left');
174-
expect(navPrev.hasClass('ng-hide')).toBe(true);
176+
expect(navPrev.hasClass('disabled')).toBe(true);
175177
});
176178

177-
it('should not show next button when last slide is active and noWrap is truthy', function() {
179+
it('should disable next button when last slide is active and noWrap is truthy', function() {
178180
scope.slides = [
179181
{content: 'one', index: 0},
180182
{content: 'two', index: 1}
@@ -184,12 +186,13 @@ describe('carousel', function() {
184186

185187
var $scope = elm.isolateScope();
186188
$scope.noWrap = function() {return true;};
187-
188189
$scope.next();
190+
191+
$scope.isNextDisabled();
189192
scope.$apply();
190193

191194
var navNext = elm.find('a.right');
192-
expect(navNext.hasClass('ng-hide')).toBe(true);
195+
expect(navNext.hasClass('disabled')).toBe(true);
193196
});
194197

195198
it('should show navigation when there are 3 slides', function () {

Diff for: template/carousel/carousel.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel" ng-swipe-right="prev()" ng-swipe-left="next()">
22
<div class="carousel-inner" ng-transclude></div>
3-
<a role="button" href class="left carousel-control" ng-click="prev()" ng-show="slides.length > 1" ng-hide="active === 0 && noWrap()">
3+
<a role="button" href class="left carousel-control" ng-click="prev()" ng-class="{ disabled: isPrevDisabled() }" ng-show="slides.length > 1">
44
<span aria-hidden="true" class="glyphicon glyphicon-chevron-left"></span>
55
<span class="sr-only">previous</span>
66
</a>
7-
<a role="button" href class="right carousel-control" ng-click="next()" ng-show="slides.length > 1" ng-hide="active === slides.length - 1 && noWrap()">
7+
<a role="button" href class="right carousel-control" ng-click="next()" ng-class="{ disabled: isNextDisabled() }" ng-show="slides.length > 1">
88
<span aria-hidden="true" class="glyphicon glyphicon-chevron-right"></span>
99
<span class="sr-only">next</span>
1010
</a>

0 commit comments

Comments
 (0)