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

Commit

Permalink
fix(carousel): disable prev/next arrows if noWrap and at bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Mar 29, 2016
1 parent cd90800 commit ac24557
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ angular.module('ui.bootstrap.carousel', [])
return $scope.active === slide.slide.index;
};


$scope.isPrevDisabled = function() {
return $scope.active === 0 && $scope.noWrap();
};

$scope.isNextDisabled = function() {
return $scope.active === slides.length - 1 && $scope.noWrap();
};

$scope.pause = function() {
if (!$scope.noPause) {
isPlaying = false;
Expand Down
13 changes: 8 additions & 5 deletions src/carousel/test/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,20 @@ describe('carousel', function() {
expect(navPrev.length).toBe(0);
});

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

var $scope = elm.isolateScope();
$scope.noWrap = function() {return true;};

$scope.isPrevDisabled();
scope.$apply();

var navPrev = elm.find('a.left');
expect(navPrev.hasClass('ng-hide')).toBe(true);
expect(navPrev.hasClass('disabled')).toBe(true);
});

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

var $scope = elm.isolateScope();
$scope.noWrap = function() {return true;};

$scope.next();

$scope.isNextDisabled();
scope.$apply();

var navNext = elm.find('a.right');
expect(navNext.hasClass('ng-hide')).toBe(true);
expect(navNext.hasClass('disabled')).toBe(true);
});

it('should show navigation when there are 3 slides', function () {
Expand Down
4 changes: 2 additions & 2 deletions template/carousel/carousel.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel" ng-swipe-right="prev()" ng-swipe-left="next()">
<div class="carousel-inner" ng-transclude></div>
<a role="button" href class="left carousel-control" ng-click="prev()" ng-show="slides.length > 1" ng-hide="active === 0 && noWrap()">
<a role="button" href class="left carousel-control" ng-click="prev()" ng-class="{ disabled: isPrevDisabled() }" ng-hide="slides.length < 1">
<span aria-hidden="true" class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">previous</span>
</a>
<a role="button" href class="right carousel-control" ng-click="next()" ng-show="slides.length > 1" ng-hide="active === slides.length - 1 && noWrap()">
<a role="button" href class="right carousel-control" ng-click="next()" ng-class="{ disabled: isNextDisabled() }" ng-hide="slides.length < 1">
<span aria-hidden="true" class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">next</span>
</a>
Expand Down

0 comments on commit ac24557

Please sign in to comment.