Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 87 additions & 1 deletion packages/fiori/cypress/specs/MediaGallery.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,94 @@ describe("MediaGallery layout", () => {

cy.get("[ui5-media-gallery] [ui5-media-gallery-item]").then($items => {
const itemsCount = $items.length;

cy.get("[ui5-media-gallery]").should("have.prop", "_overflowSize", itemsCount);
});
});
});

describe("MediaGallery accessibility", () => {
it("thumbnail list has role='listbox' and each thumbnail has role='option' and aria-selected", () => {
cy.mount(
<MediaGallery>
<MediaGalleryItem selected>
<img src="./img/HT-1000.jpg" />
<img src="./img/HT-1000.jpg" slot="thumbnail" />
</MediaGalleryItem>
<MediaGalleryItem>
<img src="./img/HT-1010.jpg" />
<img src="./img/HT-1010.jpg" slot="thumbnail" />
</MediaGalleryItem>
</MediaGallery>
);

cy.get("[ui5-media-gallery]")
.shadow()
.find(".ui5-media-gallery-thumbnails-wrapper ul")
.should("have.attr", "role", "listbox");

cy.get("[ui5-media-gallery]")
.shadow()
.find(".ui5-media-gallery-thumbnail")
.each($item => {
expect($item).to.have.attr("role", "option");
expect($item).to.have.attr("aria-checked", "true");
});
});

it("selected thumbnail has aria-selected='true', unselected has aria-selected='false'", () => {
cy.mount(
<MediaGallery>
<MediaGalleryItem selected>
<img src="./img/HT-1000.jpg" />
<img src="./img/HT-1000.jpg" slot="thumbnail" />
</MediaGalleryItem>
<MediaGalleryItem>
<img src="./img/HT-1010.jpg" />
<img src="./img/HT-1010.jpg" slot="thumbnail" />
</MediaGalleryItem>
</MediaGallery>
);

cy.get("[ui5-media-gallery]")
.shadow()
.find(".ui5-media-gallery-thumbnail")
.first()
.should("have.attr", "aria-checked", "true");

cy.get("[ui5-media-gallery]")
.shadow()
.find(".ui5-media-gallery-thumbnail")
.last()
.should("have.attr", "aria-checked", "false");
});

it("overflow list item has role='option' and aria-checked='false'", () => {
cy.mount(
<div style={{ width: "120px" }}>
<MediaGallery>
<MediaGalleryItem>
<img src="./img/HT-1000.jpg" />
<img src="./img/HT-1000.jpg" slot="thumbnail" />
</MediaGalleryItem>
<MediaGalleryItem>
<img src="./img/HT-1010.jpg" />
<img src="./img/HT-1010.jpg" slot="thumbnail" />
</MediaGalleryItem>
<MediaGalleryItem>
<img src="./img/HT-1022.jpg" />
<img src="./img/HT-1022.jpg" slot="thumbnail" />
</MediaGalleryItem>
</MediaGallery>
</div>
);

cy.get("[ui5-media-gallery]")
.shadow()
.find(".ui5-media-gallery-overflow")
.should(($li) => {
expect($li).to.have.attr("role", "option");
expect($li).to.have.attr("aria-checked", "false");
});
});
});
3 changes: 2 additions & 1 deletion packages/fiori/src/MediaGalleryTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ export default function MediaGalleryTemplate(this: MediaGallery) {
</div>

{this._showThumbnails && <div class="ui5-media-gallery-thumbnails-wrapper">
<ul>
<ul role="listbox">
{this._visibleItems.map(item =>
<li id={item.id}
class="ui5-media-gallery-thumbnail"
role="option"
aria-checked={item.selected}
onClick={this._onThumbnailClick}
>
<slot name={item._individualSlot}></slot>
Expand Down
Loading