Skip to content

Commit 37ee83f

Browse files
authored
fix(ui5-carousel): add all visible items to tab chain (#2530)
Fixes: #1996
1 parent 455f614 commit 37ee83f

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

packages/main/src/Carousel.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const metadata = {
103103
},
104104

105105
/**
106-
* Defines when the <code>load-more</code> event is thrown. If not applied the event will not be thrown.
106+
* Defines when the <code>load-more</code> event is fired. If not applied the event will not be fired.
107107
* @type {Integer}
108108
* @defaultvalue 1
109109
* @public
@@ -185,7 +185,7 @@ const metadata = {
185185

186186
/**
187187
* Fired for the last items of the <code>ui5-carousel</code> if it is scrolled and the direction of scrolling is to the end.
188-
* The number of items for which the event is thrown is controlled by the <code>infiniteScrollOffset</code> property.
188+
* The number of items for which the event is fired is controlled by the <code>infiniteScrollOffset</code> property.
189189
* @event sap.ui.webcomponents.main.Carousel#load-more
190190
* @public
191191
* @since 1.0.0-rc.8
@@ -377,14 +377,15 @@ class Carousel extends UI5Element {
377377
*/
378378
get items() {
379379
return this.content.map((item, idx) => {
380+
const visible = this.isItemInViewport(idx);
380381
return {
381382
id: `${this._id}-carousel-item-${idx + 1}`,
382383
item,
383-
tabIndex: idx === this.selectedIndex ? "0" : "-1",
384+
tabIndex: visible ? "0" : "-1",
384385
posinset: idx + 1,
385386
setsize: this.content.length,
386387
width: this._itemWidth,
387-
classes: this.isItemInViewport(idx) ? "" : "ui5-carousel-item--hidden",
388+
classes: visible ? "" : "ui5-carousel-item--hidden",
388389
};
389390
});
390391
}

packages/main/test/pages/Carousel.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727
</style>
2828

29-
<ui5-carousel items-per-page-s="3" items-per-page-m="3" items-per-page-l="3">
29+
<ui5-carousel id="carouselCards" items-per-page-s="3" items-per-page-m="3" items-per-page-l="3">
3030
<ui5-card id="card" status="1 of 11" heading="Quick Links" subheading="quick links" header-interactive
3131
class="myCard">
3232
<ui5-list id="myList3" separators="Inner">

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

+20-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ describe("Carousel general interaction", () => {
6565
assert.strictEqual(pageIndicatorDot1.getAttribute("aria-label"), PAGE_INDICATOR_ARIA_LABEL1, "The aria-label of page indicator is correct.");
6666
assert.strictEqual(pageIndicatorDot2.getAttribute("aria-label"), PAGE_INDICATOR_ARIA_LABEL2, "The aria-label of page indicator is correct.");
6767

68-
6968
const carouselItem3 = carousel.shadow$(".ui5-carousel-item:nth-child(3)");
7069
const carouselItem4 = carousel.shadow$(".ui5-carousel-item:nth-child(4)");
7170
const CAROUSEL_ITEM3_POS = "3";
@@ -90,13 +89,29 @@ describe("Carousel general interaction", () => {
9089
assert.strictEqual(carouselRoot.getAttribute("aria-activedescendant"), ACTIVEDESCENDANT_PAGE_2, "The aria-activedescendant of carousel is correct.");
9190
});
9291

92+
it("all visible elements in the current page have correct tabindex values", () => {
93+
const carousel = browser.$("#carouselCards");
94+
95+
const visibleItems = [
96+
carousel.shadow$(".ui5-carousel-item:nth-child(1) slot"),
97+
carousel.shadow$(".ui5-carousel-item:nth-child(2) slot"),
98+
carousel.shadow$(".ui5-carousel-item:nth-child(3) slot"),
99+
];
100+
101+
assert.strictEqual(
102+
visibleItems.every(el => el.getAttribute("tabindex") === "0"),
103+
true,
104+
"all visible items have correct tabindex values"
105+
);
106+
});
107+
93108
it("Arrows and Dots not displayed in case of single page", () => {
94109
const carousel = browser.$("#carousel6");
95110
const pages = carousel.getProperty("pagesCount");
96111
const pageIndicator = carousel.shadow$(".ui5-carousel-navigation-wrapper");
97112
const navigationArrows = carousel.shadow$(".ui5-carousel-navigation-arrows");
98113

99-
assert.ok(!pageIndicator.isExisting(), "Page indicator is not srendered");
114+
assert.ok(!pageIndicator.isExisting(), "Page indicator is not rendered");
100115
assert.ok(!navigationArrows.isExisting(), "Navigation arrows are not rendered");
101116
assert.strictEqual(pages, 1, "There is only 1 page.");
102117
});
@@ -149,7 +164,7 @@ describe("Carousel general interaction", () => {
149164
assert.strictEqual(eventCounter.getProperty("value"), "6", "The navigate event is not fired as no previous item.");
150165
});
151166

152-
it("loadMore event is thrown only when neccessary", () => {
167+
it("loadMore event is fired only when neccessary", () => {
153168
const carousel = browser.$("#carousel9");
154169
const eventCounter = browser.$("#loadmore-result");
155170
const navigationArrowForward = carousel.shadow$("ui5-button[arrow-forward]");
@@ -161,12 +176,12 @@ describe("Carousel general interaction", () => {
161176
navigationArrowForward.click();
162177
navigationArrowForward.click();
163178

164-
assert.strictEqual(eventCounter.getProperty("value"), "0" , "loadMore event is not thrown");
179+
assert.strictEqual(eventCounter.getProperty("value"), "0" , "loadMore event is not fired");
165180

166181
navigationArrowForward.click();
167182
navigationArrowForward.click();
168183
navigationArrowForward.click();
169184

170-
assert.strictEqual(eventCounter.getProperty("value"), "3", "loadMore event is thrown 3 times");
185+
assert.strictEqual(eventCounter.getProperty("value"), "3", "loadMore event is fired 3 times");
171186
});
172187
});

0 commit comments

Comments
 (0)