Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions packages/main/cypress/specs/Form.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,35 @@ describe("Accessibility", () => {
.should("have.attr", "aria-label", "basic form");
});

it("tests 'aria-label' via 'accessibleNameRef'", () => {
cy.mount(
<>
<span id="lbl">basic form</span>
<Form headerText="Form header text" accessibleNameRef="lbl">
<FormItem>
<Label>Name:</Label>
<Text>Red Point Stores</Text>
</FormItem>
<FormItem>
<Label>Twitter:</Label>
<Text>@sap</Text>
</FormItem>
<FormItem>
<Label>Name:</Label>
<Text>Red Point Stores</Text>
</FormItem>
</Form>
</>);

cy.get("[ui5-form]")
.as("form");

cy.get("@form")
.shadow()
.find(".ui5-form-root")
.should("have.attr", "aria-label", "basic form");
});

describe("FormGroup accessibility", () => {
it("tests 'aria-label' default", () => {
cy.mount(<Form>
Expand Down
16 changes: 13 additions & 3 deletions packages/main/src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
import type { AriaRole } from "@ui5/webcomponents-base";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";

// Template
import FormTemplate from "./FormTemplate.js";
Expand Down Expand Up @@ -229,6 +230,15 @@ class Form extends UI5Element {
@property()
accessibleName?: string;

/**
* Defines id (or many ids) of the element (or elements) that label the component.
* @default undefined
* @public
* @since 2.16.0
*/
@property()
accessibleNameRef?: string;

/**
* Defines the accessibility mode of the component in "edit" and "display" use-cases.
*
Expand Down Expand Up @@ -569,15 +579,15 @@ class Form extends UI5Element {
}

get effectiveAccessibleName() {
if (this.accessibleName) {
return this.accessibleName;
if (this.accessibleName || this.accessibleNameRef) {
return getEffectiveAriaLabelText(this);
}

return this.hasHeader ? undefined : Form.i18nBundle.getText(FORM_ACCESSIBLE_NAME);
}

get effectiveАccessibleNameRef(): string | undefined {
if (this.accessibleName) {
if (this.accessibleName || this.accessibleNameRef) {
return;
}

Expand Down
Loading