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

Commit aedc056

Browse files
mraibleajoslin
authored andcommitted
feat(carousel): Hide navigation indicators if only one slide
1 parent ca1d1e5 commit aedc056

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/carousel/test/carousel.spec.js

+31
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,37 @@ describe('carousel', function() {
6363
var indicators = elm.find('ol.carousel-indicators > li');
6464
expect(indicators.length).toBe(3);
6565
});
66+
67+
it('should hide navigation when only one slide', function () {
68+
scope.slides=[{active:false,content:'one'}];
69+
scope.$apply();
70+
elm = $compile(
71+
'<carousel interval="interval" no-transition="true">' +
72+
'<slide ng-repeat="slide in slides" active="slide.active">' +
73+
'{{slide.content}}' +
74+
'</slide>' +
75+
'</carousel>'
76+
)(scope);
77+
var indicators = elm.find('ol.carousel-indicators > li');
78+
expect(indicators.length).toBe(0);
79+
80+
var navNext = elm.find('a.right');
81+
expect(navNext.length).toBe(0);
82+
83+
var navPrev = elm.find('a.left');
84+
expect(navPrev.length).toBe(0);
85+
});
86+
87+
it('should show navigation when there are 3 slides', function () {
88+
var indicators = elm.find('ol.carousel-indicators > li');
89+
expect(indicators.length).not.toBe(0);
90+
91+
var navNext = elm.find('a.right');
92+
expect(navNext.length).not.toBe(0);
93+
94+
var navPrev = elm.find('a.left');
95+
expect(navPrev.length).not.toBe(0);
96+
});
6697

6798
it('should go to next when clicking next button', function() {
6899
var navNext = elm.find('a.right');

template/carousel/carousel.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel">
2-
<ol class="carousel-indicators">
2+
<ol class="carousel-indicators" ng-show="slides().length > 1">
33
<li ng-repeat="slide in slides()" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
44
</ol>
55
<div class="carousel-inner" ng-transclude></div>
6-
<a ng-click="prev()" class="carousel-control left">&lsaquo;</a>
7-
<a ng-click="next()" class="carousel-control right">&rsaquo;</a>
6+
<a ng-click="prev()" class="carousel-control left" ng-show="slides().length > 1">&lsaquo;</a>
7+
<a ng-click="next()" class="carousel-control right" ng-show="slides().length > 1">&rsaquo;</a>
88
</div>

0 commit comments

Comments
 (0)