Skip to content

Commit cebbd3e

Browse files
committed
add fallback for aria-label if nothing else is given
1 parent 02303c4 commit cebbd3e

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎src/cmem/ActivityControl/ActivityExecutionErrorReportModal.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface ActivityExecutionErrorReportModalProps extends Pick<ModalProps, "aria-
1111
* If set, it is used as the accessible name of the dialog via `aria-labelledby`
1212
* (unless `aria-labelledby` is given explicitly), so `aria-label` is ignored.
1313
* Use `aria-label` only for modals without title.
14+
* If neither `title`, `aria-label` nor `aria-labelledby` is set, then "Activity execution error report" is used as `aria-label`.
1415
*/
1516
title?: string;
1617
// Called when the close button is clicked
@@ -57,7 +58,7 @@ export const ActivityExecutionErrorReportModal = ({
5758
return (
5859
<SimpleDialog
5960
title={title}
60-
aria-label={ariaLabel}
61+
aria-label={ariaLabel ?? (!title && !ariaLabelledby ? "Activity execution error report" : undefined)}
6162
aria-labelledby={ariaLabelledby}
6263
isOpen={true}
6364
size="large"

‎src/cmem/ActivityControl/SilkActivityControl.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ interface IErrorReportAction extends Pick<ModalProps, "aria-label" | "aria-label
9797
* If set, it is used as the accessible name of the dialog via `aria-labelledby`
9898
* (unless `aria-labelledby` is given explicitly), so `aria-label` is ignored.
9999
* Use `aria-label` only for modals without title.
100+
* If neither `title`, `aria-label` nor `aria-labelledby` is set, then `translate("showErrorReport")` is used as `aria-label`.
100101
*/
101102
title?: string;
102103
// The element that will be rendered in the modal, either as Markdown or object
@@ -368,7 +369,12 @@ export function useSilkActivityControl({
368369
{errorReport && failureReportAction && (
369370
<ActivityExecutionErrorReportModal
370371
title={failureReportAction.title}
371-
aria-label={failureReportAction["aria-label"]}
372+
aria-label={
373+
failureReportAction["aria-label"] ??
374+
(!failureReportAction.title && !failureReportAction["aria-labelledby"]
375+
? translate("showErrorReport")
376+
: undefined)
377+
}
372378
aria-labelledby={failureReportAction["aria-labelledby"]}
373379
key={"error-report-modal"}
374380
closeButtonValue={failureReportAction.closeButtonValue}

‎src/cmem/ActivityControl/tests/SilkActivityControl.test.tsx‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
33

44
import "@testing-library/jest-dom";
55

6+
import { ActivityExecutionErrorReportModal } from "../ActivityExecutionErrorReportModal";
67
import { SilkActivityControl, SilkActivityControlProps } from "../SilkActivityControl";
78

89
type FailureReportAction = NonNullable<SilkActivityControlProps["failureReportAction"]>;
@@ -72,6 +73,15 @@ describe("SilkActivityControl error report", () => {
7273
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
7374
});
7475

76+
it("uses the translated `showErrorReport` text as fallback name for a titleless error report dialog", async () => {
77+
const warnSpy = jest.spyOn(console, "warn").mockImplementation(() => undefined);
78+
const { openErrorReport } = renderFailedActivity({ title: "" });
79+
openErrorReport();
80+
expect(await screen.findByRole("dialog", { name: "showErrorReport" })).toHaveAttribute("aria-modal", "true");
81+
expect(warnSpy).not.toHaveBeenCalled();
82+
warnSpy.mockRestore();
83+
});
84+
7585
it("forwards `aria-labelledby` to a titleless error report dialog", async () => {
7686
const { openErrorReport } = renderFailedActivity(
7787
{ "aria-labelledby": "external-report-label" },
@@ -82,3 +92,18 @@ describe("SilkActivityControl error report", () => {
8292
expect(dialog).toHaveAttribute("aria-labelledby", "external-report-label");
8393
});
8494
});
95+
96+
describe("ActivityExecutionErrorReportModal", () => {
97+
it("uses an english fallback name if neither title nor aria attributes are given", () => {
98+
render(
99+
<ActivityExecutionErrorReportModal
100+
onDiscard={jest.fn()}
101+
report={<p>Error details</p>}
102+
downloadButtonValue="Download"
103+
closeButtonValue="Close"
104+
fetchErrorReport={async () => "Error details"}
105+
/>,
106+
);
107+
expect(screen.getByRole("dialog", { name: "Activity execution error report" })).toBeInTheDocument();
108+
});
109+
});

0 commit comments

Comments
 (0)