Skip to content

Commit 1101b09

Browse files
authored
feat(ui5-list): add growing-button-accessible-name for More button (#11603)
- Add accessibilityAttributes property with growingButton.name field - Add growingButtonAriaLabel and growingButtonAriaLabelledBy getters - Update template to use new accessibility getters - Add cypress test for growing button accessible name - Add info for the newly supported property in the docs Related to: #10671, #10907
1 parent e222808 commit 1101b09

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

docs/2-advanced/09-accessibility.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ The `accessibilityAttributes` property is currently supported in:
312312
* [ShellBar](https://sap.github.io/ui5-webcomponents/nightly/components/fiori/ShellBar/)
313313
* [ShellBarItem](https://sap.github.io/ui5-webcomponents/nightly/components/fiori/ShellBarItem/)
314314
* [MenuItem](https://sap.github.io/ui5-webcomponents/nightly/components/MenuItem/)
315+
* [List](https://sap.github.io/ui5-webcomponents/nightly/components/List/)
315316

316317
---
317318

packages/main/cypress/specs/List.cy.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,35 @@ describe("List Tests", () => {
151151
.find("[id$='growing-btn']")
152152
.should("be.focused");
153153
});
154+
155+
it("tests growing button accessible name property", () => {
156+
cy.mount(
157+
<List growing="Button">
158+
<ListItemStandard>Laptop Lenovo</ListItemStandard>
159+
<ListItemStandard>IPhone 3</ListItemStandard>
160+
<ListItemStandard>HP Monitor 24</ListItemStandard>
161+
</List>
162+
);
163+
164+
cy.get("[ui5-list]")
165+
.as("list");
166+
167+
cy.get("@list").invoke('prop', 'accessibilityAttributes', {
168+
growingButton: {
169+
name: "Load more products from catalog"
170+
}
171+
});
172+
173+
cy.get("@list")
174+
.shadow()
175+
.find("[id$='growing-btn']")
176+
.should("have.attr", "aria-label", "Load more products from catalog");
177+
178+
cy.get("@list")
179+
.shadow()
180+
.find("[id$='growing-btn']")
181+
.should("not.have.attr", "aria-labelledby");
182+
});
154183
});
155184

156185
describe("List - Accessibility", () => {

packages/main/src/List.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ type ListItemClickEventDetail = {
113113

114114
type ListMoveEventDetail = MoveEventDetail;
115115

116+
type ListAccessibilityAttributes = {
117+
growingButton?: {
118+
name?: string,
119+
},
120+
}
121+
116122
/**
117123
* @class
118124
*
@@ -402,6 +408,26 @@ class List extends UI5Element {
402408
@property()
403409
accessibleName?: string;
404410

411+
/**
412+
* Defines additional accessibility attributes on different areas of the component.
413+
*
414+
* The accessibilityAttributes object has the following field:
415+
*
416+
* - **growingButton**: `growingButton.name`.
417+
*
418+
* The accessibility attributes support the following values:
419+
*
420+
* - **name**: Defines the accessible ARIA name of the growing button.
421+
* Accepts any string.
422+
*
423+
* **Note:** The `accessibilityAttributes` property is in an experimental state and is a subject to change.
424+
* @default {}
425+
* @public
426+
* @since 2.13.0
427+
*/
428+
@property({ type: Object })
429+
accessibilityAttributes: ListAccessibilityAttributes = {};
430+
405431
/**
406432
* Defines the IDs of the elements that label the component.
407433
* @default undefined
@@ -694,6 +720,14 @@ class List extends UI5Element {
694720
return this._associatedDescriptionRefTexts || getEffectiveAriaDescriptionText(this) || this._getDescriptionForGroups();
695721
}
696722

723+
get growingButtonAriaLabel() {
724+
return this.accessibilityAttributes.growingButton?.name;
725+
}
726+
727+
get growingButtonAriaLabelledBy() {
728+
return this.accessibilityAttributes.growingButton?.name ? undefined : `${this._id}-growingButton-text`;
729+
}
730+
697731
get scrollContainer() {
698732
return this.shadowRoot!.querySelector<HTMLElement>(".ui5-list-scroll-container");
699733
}
@@ -1454,4 +1488,5 @@ export type {
14541488
ListItemToggleEventDetail,
14551489
ListSelectionChangeEventDetail,
14561490
ListMoveEventDetail,
1491+
ListAccessibilityAttributes,
14571492
};

packages/main/src/ListTemplate.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ function moreRow(this: List) {
9292
"ui5-growing-button-inner": true,
9393
"ui5-growing-button-inner-active": this._loadMoreActive,
9494
}}
95-
aria-labelledby={`${this._id}-growingButton-text`}
95+
aria-label={this.growingButtonAriaLabel}
96+
aria-labelledby={this.growingButtonAriaLabelledBy}
9697
onClick={this._onLoadMoreClick}
9798
onKeyDown={this._onLoadMoreKeydown}
9899
onKeyUp={this._onLoadMoreKeyup}

0 commit comments

Comments
 (0)