Skip to content

Commit 655ec49

Browse files
authored
fix(ui5-carousel): hide navigation arrows on mouse out (#3174)
1 parent 13f9d99 commit 655ec49

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

packages/main/src/Carousel.hbs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
role="listbox"
55
aria-activedescendant="{{ariaActiveDescendant}}"
66
@keydown={{_onkeydown}}
7+
@mouseout="{{_onmouseout}}"
8+
@mouseover="{{_onmouseover}}"
79
>
810
<div class="ui5-carousel-viewport {{classes.viewport}}">
911
<div class="{{classes.content}}" style="{{styles.content}}">
@@ -28,7 +30,7 @@
2830
</div>
2931
{{/if}}
3032

31-
{{#if showNavigationArrows}}
33+
{{#if showNavigation}}
3234
<div class="{{classes.navigation}}">
3335
{{#if arrows.navigation}}
3436
{{> arrow-back}}

packages/main/src/Carousel.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ const metadata = {
152152
_itemWidth: {
153153
type: Integer,
154154
},
155+
156+
/**
157+
* If set to true navigation arrows are shown
158+
* @private
159+
* @since 1.0.0-rc.15
160+
*/
161+
_visibleNavigationArrows: {
162+
type: Boolean,
163+
noAttribute: true,
164+
},
155165
},
156166
managedSlots: true,
157167
slots: /** @lends sap.ui.webcomponents.main.Carousel.prototype */ {
@@ -335,6 +345,14 @@ class Carousel extends UI5Element {
335345
}
336346
}
337347

348+
_onmouseout() {
349+
this._visibleNavigationArrows = false;
350+
}
351+
352+
_onmouseover() {
353+
this._visibleNavigationArrows = true;
354+
}
355+
338356
navigateLeft() {
339357
this._resizing = false;
340358

@@ -432,12 +450,12 @@ class Carousel extends UI5Element {
432450
content: {
433451
"ui5-carousel-content": true,
434452
"ui5-carousel-content-no-animation": this.supressAimation,
435-
"ui5-carousel-content-has-navigation": this.showNavigationArrows,
436-
"ui5-carousel-content-has-navigation-and-buttons": this.showNavigationArrows && this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
453+
"ui5-carousel-content-has-navigation": this.showNavigation,
454+
"ui5-carousel-content-has-navigation-and-buttons": this.showNavigation && this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
437455
},
438456
navigation: {
439457
"ui5-carousel-navigation-wrapper": true,
440-
"ui5-carousel-navigation-with-buttons": this.showNavigationArrows && this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
458+
"ui5-carousel-navigation-with-buttons": this.showNavigation && this.arrowsPlacement === CarouselArrowsPlacement.Navigation,
441459
},
442460
navPrevButton: {
443461
"ui5-carousel-navigation-button--hidden": !this.hasPrev,
@@ -472,7 +490,7 @@ class Carousel extends UI5Element {
472490
}
473491

474492
get arrows() {
475-
const showArrows = this.showNavigationArrows && isDesktop();
493+
const showArrows = this._visibleNavigationArrows && this.showNavigation && isDesktop();
476494

477495
return {
478496
content: showArrows && this.arrowsPlacement === CarouselArrowsPlacement.Content,
@@ -500,7 +518,7 @@ class Carousel extends UI5Element {
500518
return this._isRTL ? this.pagesCount - (this.pagesCount - this.selectedIndex) + 1 : this.selectedIndex + 1;
501519
}
502520

503-
get showNavigationArrows() {
521+
get showNavigation() {
504522
return !this.hideNavigation && this.pagesCount > 1;
505523
}
506524

packages/main/src/themes/Carousel.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
.ui5-carousel-navigation-arrows {
7676
width: 100%;
77-
padding:0 1.5rem;
77+
padding:0 0.5rem;
7878
position: absolute;
7979
top: calc(50% - 2.5rem);
8080
left: 0;

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ describe("Carousel general interaction", () => {
1515

1616
it("Carousel navigates left", () => {
1717
const carousel = browser.$("#carousel1");
18+
carousel.scrollIntoView();
19+
carousel.moveTo();
1820
const carouselRightButton = carousel.shadow$$(".ui5-carousel-navigation-button")[0];
1921

2022
carouselRightButton.click();
@@ -23,6 +25,8 @@ describe("Carousel general interaction", () => {
2325

2426
it("Carousel navigates right", () => {
2527
const carousel = browser.$("#carousel1");
28+
carousel.scrollIntoView();
29+
carousel.moveTo();
2630
const carouselLeftButton = carousel.shadow$$(".ui5-carousel-navigation-button")[1];
2731

2832
carouselLeftButton.click();
@@ -31,20 +35,26 @@ describe("Carousel general interaction", () => {
3135

3236
it("Navigation is rendered for carousel with less than 9 elements", () => {
3337
const carousel = browser.$("#carousel1");
38+
carousel.moveTo();
39+
3440
const navigation = carousel.shadow$(".ui5-carousel-navigation > div");
3541

3642
assert.ok(navigation.isExisting(), "Navigation is rendered");
3743
});
3844

3945
it("Navigation is rendered for carousel with more than 9 elements", () => {
4046
const carousel = browser.$("#carousel2");
47+
carousel.scrollIntoView();
48+
carousel.moveTo();
4149
const navigation = carousel.shadow$(".ui5-carousel-navigation > ui5-label");
4250

4351
assert.ok(navigation.isExisting(), "Navigation is rendered");
4452
});
4553

4654
it("Buttons are rendered in the navigation(arrows-placement)", () => {
4755
const carousel = browser.$("#carousel3");
56+
carousel.scrollIntoView();
57+
carousel.moveTo();
4858
const buttons = carousel.shadow$$(".ui5-carousel-navigation-wrapper ui5-button");
4959

5060
assert.strictEqual(buttons.length, 2, "Navigation is rendered");
@@ -59,7 +69,9 @@ describe("Carousel general interaction", () => {
5969

6070
it("Aria attributes are set", () => {
6171
const carousel = browser.$("#carousel5");
62-
const pageIndicatorDot1 = carousel.shadow$(".ui5-carousel-navigation-dot:first-child");
72+
carousel.scrollIntoView();
73+
carousel.moveTo();
74+
const pageIndicatorDot1 = $('#carousel5').shadow$(".ui5-carousel-navigation-dot:first-child");
6375
const pageIndicatorDot2 = carousel.shadow$(".ui5-carousel-navigation-dot:nth-child(2)");
6476
const PAGE_INDICATOR_ARIA_LABEL1 = "Item 1 of 5 displayed";
6577
const PAGE_INDICATOR_ARIA_LABEL2 = "Item 2 of 5 displayed";
@@ -130,6 +142,8 @@ describe("Carousel general interaction", () => {
130142

131143
it("Event navigate fired when pressing navigation arrows", () => {
132144
const carousel = browser.$("#carousel8");
145+
carousel.scrollIntoView();
146+
carousel.moveTo();
133147
const selectedIndex = browser.$("#result");
134148
const eventCounter = browser.$("#resultCounter");
135149
const navigationArrowForward = carousel.shadow$("ui5-button[arrow-forward]");
@@ -170,6 +184,8 @@ describe("Carousel general interaction", () => {
170184
it("loadMore event is fired only when neccessary", () => {
171185
const carousel = browser.$("#carousel9");
172186
const eventCounter = browser.$("#loadmore-result");
187+
carousel.scrollIntoView();
188+
carousel.moveTo();
173189
const navigationArrowForward = carousel.shadow$("ui5-button[arrow-forward]");
174190

175191
navigationArrowForward.click();

0 commit comments

Comments
 (0)