Skip to content
71 changes: 71 additions & 0 deletions packages/fiori/cypress/specs/DynamicSideContent.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,77 @@ describe("Accessibility", () => {
.find(".ui5-dsc-side")
.should("have.attr", "aria-label", customSideContentLabel);
});

it("tests no role when explicitly set to undefined via accessibilityAttributes", () => {
cy.mount(
<DynamicSideContent>
<div>
<h1>Main Content</h1>
</div>
<div slot="sideContent">
<h1>Side Content</h1>
</div>
</DynamicSideContent>
);

cy.get("[ui5-dynamic-side-content]")
.as("dsc");

cy.get<DynamicSideContent>("@dsc")
.then($dsc => {
$dsc.get(0).accessibilityAttributes = {
mainContent: { role: undefined },
sideContent: { role: undefined },
};
});

cy.get("@dsc")
.shadow()
.find(".ui5-dsc-main")
.should("not.have.attr", "role");

cy.get("@dsc")
.shadow()
.find(".ui5-dsc-side")
.should("not.have.attr", "role");
});

it("tests custom roles via accessibilityAttributes", () => {
const customMainRole = "region";
const customSideRole = "note";

cy.mount(
<DynamicSideContent>
<div>
<h1>Main Content</h1>
</div>
<div slot="sideContent">
<h1>Side Content</h1>
</div>
</DynamicSideContent>
);

cy.get("[ui5-dynamic-side-content]")
.as("dsc");

cy.get<DynamicSideContent>("@dsc")
.then($dsc => {
$dsc.get(0).accessibilityAttributes = {
mainContent: { role: customMainRole },
sideContent: { role: customSideRole },
};
});

cy.get("@dsc")
.shadow()
.find(".ui5-dsc-main")
.should("have.attr", "role", customMainRole);

cy.get("@dsc")
.shadow()
.find(".ui5-dsc-side")
.should("have.attr", "role", customSideRole);
});
});

describe("'sideContentPosition' property", () => {
Expand Down
22 changes: 17 additions & 5 deletions packages/fiori/src/DynamicSideContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type DynamicSideContentLayoutChangeEventDetail = {
sideContentVisible: boolean,
}

type DynamicSideContentAriaAccessibilityAttributes = Pick<AccessibilityAttributes, "ariaLabel">;
type DynamicSideContentAriaAccessibilityAttributes = Pick<AccessibilityAttributes, "ariaLabel" | "role">;
type DynamicSideContentAccessibilityAttributes = {
mainContent?: DynamicSideContentAriaAccessibilityAttributes,
sideContent?: DynamicSideContentAriaAccessibilityAttributes,
Expand Down Expand Up @@ -201,8 +201,13 @@ class DynamicSideContent extends UI5Element {
*
* The accessibilityAttributes object has the following fields:
*
* - **mainContent**: `mainContent.ariaLabel` defines the aria-label of the main content area. Accepts any string.
* - **sideContent**: `sideContent.ariaLabel` defines the aria-label of the side content area. Accepts any string.
* - **mainContent**:
* - **ariaLabel**: defines the aria-label of the main content area. Accepts any string.
* - **role**: defines the role of the main content area. When not set, defaults to `"main"`. Set to `undefined` to remove the role attribute.
*
* - **sideContent**:
* - **ariaLabel**: defines the aria-label of the side content area. Accepts any string.
* - **role**: defines the role of the side content area. When not set, defaults to `"complementary"`. Set to `undefined` to remove the role attribute.
*
* @default {}
* @public
Expand Down Expand Up @@ -370,12 +375,19 @@ class DynamicSideContent extends UI5Element {
}

get accInfo(): DynamicSideContentAccessibilityAttributes {
const mainContentAttr = this.accessibilityAttributes.mainContent || {};
const sideContentAttr = this.accessibilityAttributes.sideContent || {};
const hasMainRole = "role" in mainContentAttr;
const hasSideRole = "role" in sideContentAttr;

Comment thread
NHristov-sap marked this conversation as resolved.
return {
mainContent: {
ariaLabel: this.accessibilityAttributes.mainContent?.ariaLabel || DynamicSideContent.i18nBundle.getText(DSC_MAIN_ARIA_LABEL),
ariaLabel: mainContentAttr.ariaLabel || DynamicSideContent.i18nBundle.getText(DSC_MAIN_ARIA_LABEL),
role: hasMainRole ? mainContentAttr.role : "main",
},
sideContent: {
ariaLabel: this.accessibilityAttributes.sideContent?.ariaLabel || DynamicSideContent.i18nBundle.getText(DSC_SIDE_ARIA_LABEL),
ariaLabel: sideContentAttr.ariaLabel || DynamicSideContent.i18nBundle.getText(DSC_SIDE_ARIA_LABEL),
role: hasSideRole ? sideContentAttr.role : "complementary",
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fiori/src/DynamicSideContentTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function DynamicSideContentTemplate(this: DynamicSideContent) {
function mainContent(this: DynamicSideContent) {
return (
<div
role="main"
role={this.accInfo.mainContent?.role}
aria-label={this.accInfo.mainContent?.ariaLabel}
class={this.classes.main}
style={this.styles.main}
Expand All @@ -37,7 +37,7 @@ function mainContent(this: DynamicSideContent) {
function sideContent(this: DynamicSideContent) {
return (
<aside
role="complementary"
role={this.accInfo.sideContent?.role}
aria-label={this.accInfo.sideContent?.ariaLabel}
class={this.classes.side}
style={this.styles.side}
Expand Down
2 changes: 2 additions & 0 deletions packages/fiori/test/pages/DynamicSideContent.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ <h1>Side Content</h1>
dynamicSideContent.accessibilityAttributes = {
mainContent: {
ariaLabel: "Main Content Area",
role: "region",
},
sideContent: {
ariaLabel: "Side Content Area",
role: "note",
}
};
</script>
Expand Down
Loading