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

Commit a3964d4

Browse files
plondonwesleycho
authored andcommitted
feat(carousel): disable prev/next arrows if at bounds
- When at bounds and noWrap is enabled, disable the prev and next arrows when appropriate BREAKING CHANGE: This adds disabled CSS - there is a possibility this may break existing UI slightly for those adding custom CSS/making use of custom templates. Modify the template appropriately if necessary Closes #5704 Closes #5708
1 parent 434c1c5 commit a3964d4

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

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;

src/carousel/test/carousel.spec.js

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

166+
it('should disable prev button when slide index is 0 and noWrap is truthy', function() {
167+
scope.$apply();
168+
169+
var $scope = elm.isolateScope();
170+
$scope.noWrap = function() {return true;};
171+
172+
$scope.isPrevDisabled();
173+
scope.$apply();
174+
175+
var navPrev = elm.find('a.left');
176+
expect(navPrev.hasClass('disabled')).toBe(true);
177+
});
178+
179+
it('should disable next button when last slide is active and noWrap is truthy', function() {
180+
scope.slides = [
181+
{content: 'one', index: 0},
182+
{content: 'two', index: 1}
183+
];
184+
185+
scope.$apply();
186+
187+
var $scope = elm.isolateScope();
188+
$scope.noWrap = function() {return true;};
189+
$scope.next();
190+
191+
$scope.isNextDisabled();
192+
scope.$apply();
193+
194+
var navNext = elm.find('a.right');
195+
expect(navNext.hasClass('disabled')).toBe(true);
196+
});
197+
166198
it('should show navigation when there are 3 slides', function () {
167199
var indicators = elm.find('ol.carousel-indicators > li');
168200
expect(indicators.length).not.toBe(0);

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">
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">
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)