Skip to content

Commit f6c46be

Browse files
authoredApr 2, 2020
fix(ui5-carousel): hide arrows and dots when single page (#1414)
The navigation arrows and page indicator bar should be hidden when there is a single page displayed within the Carousel.Reported by the "MDK" users.
1 parent 4e2112f commit f6c46be

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed
 

‎packages/main/src/Carousel.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</div>
3636
{{/if}}
3737

38-
{{#unless hideNavigation}}
38+
{{#if showNavigationArrows}}
3939
<div class="{{classes.navigation}}">
4040
{{#if arrows.navigation}}
4141
<ui5-button
@@ -70,6 +70,6 @@
7070
></ui5-button>
7171
{{/if}}
7272
</div>
73-
{{/unless}}
73+
{{/if}}
7474
</div>
7575
</section>

‎packages/main/src/Carousel.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ class Carousel extends UI5Element {
277277
content: {
278278
"ui5-carousel-content": true,
279279
"ui5-carousel-content-no-animation": this.shouldAnimate,
280-
"ui5-carousel-content-has-navigation": !this.hideNavigation,
281-
"ui5-carousel-content-has-navigation-and-buttons": !this.hideNavigation && this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
280+
"ui5-carousel-content-has-navigation": this.showNavigationArrows,
281+
"ui5-carousel-content-has-navigation-and-buttons": this.showNavigationArrows && this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
282282
},
283283
navigation: {
284284
"ui5-carousel-navigation-wrapper": true,
285-
"ui5-carousel-navigation-with-buttons": this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
285+
"ui5-carousel-navigation-with-buttons": this.showNavigationArrows && this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
286286
},
287287
page: {
288288
"ui5-carousel-page": true,
@@ -304,9 +304,11 @@ class Carousel extends UI5Element {
304304
}
305305

306306
get arrows() {
307+
const showArrows = this.showNavigationArrows && isDesktop();
308+
307309
return {
308-
content: isDesktop() && this.arrowsPlacement === CarouselArrowsPlacement.Content,
309-
navigation: isDesktop() && this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
310+
content: showArrows && this.arrowsPlacement === CarouselArrowsPlacement.Content,
311+
navigation: showArrows && this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
310312
};
311313
}
312314

@@ -318,6 +320,10 @@ class Carousel extends UI5Element {
318320
return this.selectedIndex + 1;
319321
}
320322

323+
get showNavigationArrows() {
324+
return !this.hideNavigation && this.pages.length > 1;
325+
}
326+
321327
static async onDefine() {
322328
await Promise.all([
323329
fetchI18nBundle("@ui5/webcomponents"),

‎packages/main/test/pages/Carousel.html

+10
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,15 @@
225225
<ui5-button>Button 7</ui5-button>
226226
<ui5-button>Button 8</ui5-button>
227227
</ui5-carousel>
228+
229+
<ui5-title>Carousel with one page</ui5-title>
230+
<ui5-label>The arrows and dots are not displayed</ui5-label>
231+
232+
<ui5-carousel id="carousel6" items-per-page="3">
233+
<ui5-button>Button 1</ui5-button>
234+
<ui5-button>Button 2</ui5-button>
235+
<ui5-button>Button 3</ui5-button>
236+
</ui5-carousel>
237+
228238
</body>
229239
</html>

‎packages/main/test/specs/Carousel.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,14 @@ describe("Carousel general interaction", () => {
5454
assert.strictEqual(pages, 3, "There are only 3 pages.");
5555
});
5656

57+
it("Arrows and Dots not displayed in case of single page", () => {
58+
const carousel = browser.$("#carousel6");
59+
const pages = carousel.getProperty("pages").length;
60+
const pageIndicator = carousel.shadow$(".ui5-carousel-navigation-wrapper");
61+
const navigationArrows = carousel.shadow$(".ui5-carousel-navigation-arrows");
62+
63+
assert.ok(!pageIndicator.isExisting(), "Navigation is rendered");
64+
assert.ok(!navigationArrows.isExisting(), "Navigation is rendered");
65+
assert.strictEqual(pages, 1, "There are only 3 pages.");
66+
});
5767
});

0 commit comments

Comments
 (0)
Please sign in to comment.