Skip to content

Commit 9f2eb35

Browse files
authored
Merge pull request #441 from eccenca/feature/useModalContext-CMEM-8209
Support accessible names for titleless activity error reports
2 parents 3dc0b87 + dbd4b56 commit 9f2eb35

10 files changed

Lines changed: 549 additions & 24 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- `<SilkActivityControl />`, `<ActivityExecutionErrorReportModal />`
12+
- support `aria-label` and `aria-labelledby` for naming activity error report dialogs without a visible title
13+
- support `fullScreenTogglerTexts` to set localized texts for the full screen toggler of the error report dialog
14+
- `<SimpleDialog />`
15+
- `fullScreenTogglerTexts` property: sets the texts of the full screen toggler for the `maximize` and `minimize` state, used as `title` and accessible name of the button
16+
17+
### Changed
18+
19+
- `<SimpleDialog />`
20+
- the full screen toggler has an accessible name and a `title` now, the default texts are "Show in full screen" and "Exit full screen", use `fullScreenTogglerTexts` to localize them
21+
- `<SilkActivityControl />`, `<ActivityExecutionErrorReportModal />`
22+
- error report dialogs without title, `aria-label` and `aria-labelledby` get a fallback accessible name, `translate("showErrorReport")` in `<SilkActivityControl />` and "Activity execution error report" in `<ActivityExecutionErrorReportModal />`
23+
- the error report dialog uses the full screen toggler of `<SimpleDialog />` instead of an own implementation
24+
- `<Modal />`
25+
- the elements referenced by `aria-labelledby` are checked for existence when the modal is opened, invalid references are reported as console warning and removed from `aria-labelledby`
26+
- if none of the elements referenced by `aria-labelledby` exists then a given `aria-label` is used as fallback, without `aria-label` the `role` and `aria-modal` attributes are removed
27+
- `<SimpleDialog />`, `<AlertDialog />`
28+
- the intent state is also used as `aria-label` fallback if none of the elements referenced by `aria-labelledby` exists
29+
930
## [26.2.1] - 2026-11-02
1031

1132
### Fixed

‎src/cmem/ActivityControl/ActivityExecutionErrorReportModal.tsx‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import React, { useState } from "react";
1+
import React from "react";
22

33
import Button from "../../components/Button/Button";
4-
import SimpleDialog from "../../components/Dialog/SimpleDialog";
5-
import IconButton from "../../components/Icon/IconButton";
4+
import SimpleDialog, { SimpleDialogProps } from "../../components/Dialog/SimpleDialog";
65
import HtmlContentBlock from "../../components/Typography/HtmlContentBlock";
76

8-
interface ActivityExecutionErrorReportModalProps {
9-
// Title of the modal
7+
interface ActivityExecutionErrorReportModalProps extends Pick<
8+
SimpleDialogProps,
9+
"aria-label" | "aria-labelledby" | "fullScreenTogglerTexts"
10+
> {
11+
/**
12+
* Title of the modal.
13+
* If set, it is used as the accessible name of the dialog via `aria-labelledby`
14+
* (unless `aria-labelledby` is given explicitly), so `aria-label` is ignored.
15+
* Use `aria-label` only for modals without title.
16+
* If neither `title`, a non-empty `aria-label` nor `aria-labelledby` is set, then "Activity execution error report" is used as `aria-label`.
17+
*/
1018
title?: string;
1119
// Called when the close button is clicked
1220
onDiscard: () => any;
@@ -23,13 +31,15 @@ interface ActivityExecutionErrorReportModalProps {
2331
/** Shows the execution error report to the user and offers to download the report. */
2432
export const ActivityExecutionErrorReportModal = ({
2533
title,
34+
"aria-label": ariaLabel,
35+
"aria-labelledby": ariaLabelledby,
2636
onDiscard,
2737
report,
2838
downloadButtonValue,
2939
closeButtonValue,
40+
fullScreenTogglerTexts,
3041
fetchErrorReport,
3142
}: ActivityExecutionErrorReportModalProps) => {
32-
const [displayFullscreen, setDisplayFullscreen] = useState<boolean>(false);
3343
const fileName =
3444
"Activity execution report from " +
3545
new Date().toISOString().replace(/T/, " ").replace(/:/g, "-").substr(0, 19) +
@@ -51,15 +61,13 @@ export const ActivityExecutionErrorReportModal = ({
5161
return (
5262
<SimpleDialog
5363
title={title}
64+
aria-label={ariaLabel || "Activity execution error report"}
65+
aria-labelledby={ariaLabelledby}
5466
isOpen={true}
55-
size={displayFullscreen ? "fullscreen" : "large"}
67+
size="large"
68+
showFullScreenToggler
69+
fullScreenTogglerTexts={fullScreenTogglerTexts}
5670
onClose={onDiscard}
57-
headerOptions={
58-
<IconButton
59-
name={displayFullscreen ? "toggler-minimize" : "toggler-maximize"}
60-
onClick={() => setDisplayFullscreen(!displayFullscreen)}
61-
/>
62-
}
6371
actions={[
6472
<Button data-test-id={"error-report-download-btn"} affirmative onClick={handleDownload} key="download">
6573
{downloadButtonValue}

‎src/cmem/ActivityControl/SilkActivityControl.tsx‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Intent } from "@blueprintjs/core/src/common/intent";
33

44
import { Icon, Spacing } from "../../";
55
import { IntentTypes } from "../../common/Intent";
6+
import { SimpleDialogProps } from "../../components/Dialog/SimpleDialog";
67
import { TestableComponent } from "../../components/interfaces";
78
import { ElapsedDateTimeDisplay, ElapsedDateTimeDisplayUnits } from "../DateTimeDisplay/ElapsedDateTimeDisplay";
89

@@ -90,8 +91,17 @@ const defaultLayout: SilkActivityControlLayoutProps = {
9091
visualization: "spinner",
9192
};
9293

93-
interface IErrorReportAction {
94-
// The title of the error report modal
94+
interface IErrorReportAction extends Pick<
95+
SimpleDialogProps,
96+
"aria-label" | "aria-labelledby" | "fullScreenTogglerTexts"
97+
> {
98+
/**
99+
* The title of the error report modal.
100+
* If set, it is used as the accessible name of the dialog via `aria-labelledby`
101+
* (unless `aria-labelledby` is given explicitly), so `aria-label` is ignored.
102+
* Use `aria-label` only for modals without title.
103+
* If neither `title`, a non-empty `aria-label` nor `aria-labelledby` is set, then `translate("showErrorReport")` is used as `aria-label`.
104+
*/
95105
title?: string;
96106
// The element that will be rendered in the modal, either as Markdown or object
97107
renderReport: (report: string | SilkActivityExecutionReportProps) => React.JSX.Element;
@@ -362,9 +372,12 @@ export function useSilkActivityControl({
362372
{errorReport && failureReportAction && (
363373
<ActivityExecutionErrorReportModal
364374
title={failureReportAction.title}
375+
aria-label={failureReportAction["aria-label"] || translate("showErrorReport")}
376+
aria-labelledby={failureReportAction["aria-labelledby"]}
365377
key={"error-report-modal"}
366378
closeButtonValue={failureReportAction.closeButtonValue}
367379
downloadButtonValue={failureReportAction.downloadButtonValue}
380+
fullScreenTogglerTexts={failureReportAction.fullScreenTogglerTexts}
368381
fetchErrorReport={async () => {
369382
return (await failureReportAction.fetchErrorReport(true)) as string | undefined;
370383
}}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import React from "react";
2+
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
3+
4+
import "@testing-library/jest-dom";
5+
6+
import { ActivityExecutionErrorReportModal } from "../ActivityExecutionErrorReportModal";
7+
import { SilkActivityControl, SilkActivityControlProps } from "../SilkActivityControl";
8+
9+
type FailureReportAction = NonNullable<SilkActivityControlProps["failureReportAction"]>;
10+
11+
const renderFailedActivity = (
12+
failureReportAction: Partial<FailureReportAction>,
13+
additionalContent?: React.ReactNode,
14+
) => {
15+
const props: SilkActivityControlProps = {
16+
label: "Execution",
17+
initialStatus: {
18+
activity: "execute",
19+
activityLabel: "Execution",
20+
isRunning: false,
21+
failed: true,
22+
statusName: "Finished",
23+
progress: 100,
24+
lastUpdateTime: 0,
25+
message: "Failed",
26+
cancelled: false,
27+
concreteStatus: "Failed",
28+
},
29+
registerForUpdates: jest.fn(),
30+
unregisterFromUpdates: jest.fn(),
31+
showStartAction: false,
32+
showStopAction: false,
33+
showReloadAction: false,
34+
executeActivityAction: jest.fn(),
35+
translate: (key) => key,
36+
failureReportAction: {
37+
renderReport: () => <p>Error details</p>,
38+
renderMarkdown: true,
39+
fetchErrorReport: async () => "Error details",
40+
downloadButtonValue: "Download",
41+
closeButtonValue: "Close",
42+
...failureReportAction,
43+
},
44+
};
45+
const utils = render(
46+
<>
47+
{additionalContent}
48+
<SilkActivityControl {...props} />
49+
</>,
50+
);
51+
const openErrorReport = () =>
52+
fireEvent.click(utils.container.querySelector("[data-test-id='activity-show-error-report']") as HTMLElement);
53+
return { ...utils, openErrorReport };
54+
};
55+
56+
describe("SilkActivityControl error report", () => {
57+
it("uses the title as accessible name of the error report dialog", async () => {
58+
const { openErrorReport } = renderFailedActivity({ title: "Error report" });
59+
openErrorReport();
60+
expect(await screen.findByRole("dialog", { name: "Error report" })).toHaveAttribute("aria-modal", "true");
61+
});
62+
63+
it("forwards `aria-label` to a titleless error report dialog", async () => {
64+
const { openErrorReport } = renderFailedActivity({
65+
title: "",
66+
"aria-label": "Activity execution error report",
67+
});
68+
openErrorReport();
69+
const dialog = await screen.findByRole("dialog", { name: "Activity execution error report" });
70+
expect(dialog).toHaveAttribute("aria-modal", "true");
71+
72+
fireEvent.click(screen.getByRole("button", { name: "Close" }));
73+
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
74+
});
75+
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+
try {
79+
const { openErrorReport } = renderFailedActivity({ title: "", "aria-label": "" });
80+
openErrorReport();
81+
expect(await screen.findByRole("dialog", { name: "showErrorReport" })).toHaveAttribute(
82+
"aria-modal",
83+
"true",
84+
);
85+
expect(warnSpy).not.toHaveBeenCalled();
86+
} finally {
87+
warnSpy.mockRestore();
88+
}
89+
});
90+
91+
it("forwards the full screen toggler texts to the error report dialog", async () => {
92+
const { openErrorReport } = renderFailedActivity({
93+
title: "Error report",
94+
fullScreenTogglerTexts: { maximize: "Vollbild anzeigen", minimize: "Vollbild verlassen" },
95+
});
96+
openErrorReport();
97+
const dialog = await screen.findByRole("dialog", { name: "Error report" });
98+
const toggler = within(dialog).getByRole("button", { name: "Vollbild anzeigen" });
99+
100+
fireEvent.click(toggler);
101+
expect(toggler).toHaveAccessibleName("Vollbild verlassen");
102+
});
103+
104+
it("forwards `aria-labelledby` to a titleless error report dialog", async () => {
105+
const { openErrorReport } = renderFailedActivity(
106+
{ "aria-labelledby": "external-report-label" },
107+
<span id="external-report-label">Referenced error report label</span>,
108+
);
109+
openErrorReport();
110+
const dialog = await screen.findByRole("dialog", { name: "Referenced error report label" });
111+
expect(dialog).toHaveAttribute("aria-labelledby", "external-report-label");
112+
});
113+
});
114+
115+
describe("ActivityExecutionErrorReportModal", () => {
116+
it.each([undefined, ""])(
117+
"uses an english fallback name if neither title nor aria attributes are given (aria-label: %p)",
118+
(ariaLabel) => {
119+
render(
120+
<ActivityExecutionErrorReportModal
121+
aria-label={ariaLabel}
122+
onDiscard={jest.fn()}
123+
report={<p>Error details</p>}
124+
downloadButtonValue="Download"
125+
closeButtonValue="Close"
126+
fetchErrorReport={async () => "Error details"}
127+
/>,
128+
);
129+
expect(screen.getByRole("dialog", { name: "Activity execution error report" })).toBeInTheDocument();
130+
},
131+
);
132+
});

‎src/components/Dialog/AlertDialog.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export interface AlertDialogProps extends Omit<SimpleDialogProps, "intent" | "ro
2222
/**
2323
* Special element to display alert notification in modal dialogs.
2424
* Inherits all properties from `SimpleDialog`, except `intent` and `role`.
25-
* If `title`, `aria-label` nor a `aria-labelledby` is given then the alert level automatically used as fallback for `aria-label`.
25+
* If no `aria-label` is given then the alert level is automatically used as fallback for `aria-label`.
26+
* It is only used if there is no `title` and no valid `aria-labelledby` reference.
2627
*/
2728
export const AlertDialog = ({
2829
children,

0 commit comments

Comments
 (0)