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

Commit

Permalink
feat(carousel): Hide navigation indicators if only one slide
Browse files Browse the repository at this point in the history
  • Loading branch information
mraible authored and ajoslin committed Mar 18, 2013
1 parent ca1d1e5 commit aedc056
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
31 changes: 31 additions & 0 deletions src/carousel/test/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,37 @@ describe('carousel', function() {
var indicators = elm.find('ol.carousel-indicators > li');
expect(indicators.length).toBe(3);
});

it('should hide navigation when only one slide', function () {
scope.slides=[{active:false,content:'one'}];
scope.$apply();
elm = $compile(
'<carousel interval="interval" no-transition="true">' +
'<slide ng-repeat="slide in slides" active="slide.active">' +
'{{slide.content}}' +
'</slide>' +
'</carousel>'
)(scope);
var indicators = elm.find('ol.carousel-indicators > li');
expect(indicators.length).toBe(0);

var navNext = elm.find('a.right');
expect(navNext.length).toBe(0);

var navPrev = elm.find('a.left');
expect(navPrev.length).toBe(0);
});

it('should show navigation when there are 3 slides', function () {
var indicators = elm.find('ol.carousel-indicators > li');
expect(indicators.length).not.toBe(0);

var navNext = elm.find('a.right');
expect(navNext.length).not.toBe(0);

var navPrev = elm.find('a.left');
expect(navPrev.length).not.toBe(0);
});

it('should go to next when clicking next button', function() {
var navNext = elm.find('a.right');
Expand Down
6 changes: 3 additions & 3 deletions template/carousel/carousel.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel">
<ol class="carousel-indicators">
<ol class="carousel-indicators" ng-show="slides().length > 1">
<li ng-repeat="slide in slides()" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
</ol>
<div class="carousel-inner" ng-transclude></div>
<a ng-click="prev()" class="carousel-control left">&lsaquo;</a>
<a ng-click="next()" class="carousel-control right">&rsaquo;</a>
<a ng-click="prev()" class="carousel-control left" ng-show="slides().length > 1">&lsaquo;</a>
<a ng-click="next()" class="carousel-control right" ng-show="slides().length > 1">&rsaquo;</a>
</div>

0 comments on commit aedc056

Please sign in to comment.