Skip to content

Commit da446da

Browse files
committed
add option to translate fullscreen toggler
1 parent cebbd3e commit da446da

5 files changed

Lines changed: 51 additions & 7 deletions

File tree

‎src/cmem/ActivityControl/ActivityExecutionErrorReportModal.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React from "react";
22

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

8-
interface ActivityExecutionErrorReportModalProps extends Pick<ModalProps, "aria-label" | "aria-labelledby"> {
7+
interface ActivityExecutionErrorReportModalProps extends Pick<
8+
SimpleDialogProps,
9+
"aria-label" | "aria-labelledby" | "fullScreenTogglerTexts"
10+
> {
911
/**
1012
* Title of the modal.
1113
* If set, it is used as the accessible name of the dialog via `aria-labelledby`
@@ -35,6 +37,7 @@ export const ActivityExecutionErrorReportModal = ({
3537
report,
3638
downloadButtonValue,
3739
closeButtonValue,
40+
fullScreenTogglerTexts,
3841
fetchErrorReport,
3942
}: ActivityExecutionErrorReportModalProps) => {
4043
const fileName =
@@ -63,6 +66,7 @@ export const ActivityExecutionErrorReportModal = ({
6366
isOpen={true}
6467
size="large"
6568
showFullScreenToggler
69+
fullScreenTogglerTexts={fullScreenTogglerTexts}
6670
onClose={onDiscard}
6771
actions={[
6872
<Button data-test-id={"error-report-download-btn"} affirmative onClick={handleDownload} key="download">

‎src/cmem/ActivityControl/SilkActivityControl.tsx‎

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

44
import { Icon, Spacing } from "../../";
55
import { IntentTypes } from "../../common/Intent";
6-
import { ModalProps } from "../../components/Dialog/Modal";
6+
import { SimpleDialogProps } from "../../components/Dialog/SimpleDialog";
77
import { TestableComponent } from "../../components/interfaces";
88
import { ElapsedDateTimeDisplay, ElapsedDateTimeDisplayUnits } from "../DateTimeDisplay/ElapsedDateTimeDisplay";
99

@@ -91,7 +91,10 @@ const defaultLayout: SilkActivityControlLayoutProps = {
9191
visualization: "spinner",
9292
};
9393

94-
interface IErrorReportAction extends Pick<ModalProps, "aria-label" | "aria-labelledby"> {
94+
interface IErrorReportAction extends Pick<
95+
SimpleDialogProps,
96+
"aria-label" | "aria-labelledby" | "fullScreenTogglerTexts"
97+
> {
9598
/**
9699
* The title of the error report modal.
97100
* If set, it is used as the accessible name of the dialog via `aria-labelledby`
@@ -379,6 +382,7 @@ export function useSilkActivityControl({
379382
key={"error-report-modal"}
380383
closeButtonValue={failureReportAction.closeButtonValue}
381384
downloadButtonValue={failureReportAction.downloadButtonValue}
385+
fullScreenTogglerTexts={failureReportAction.fullScreenTogglerTexts}
382386
fetchErrorReport={async () => {
383387
return (await failureReportAction.fetchErrorReport(true)) as string | undefined;
384388
}}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
2+
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
33

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

@@ -82,6 +82,19 @@ describe("SilkActivityControl error report", () => {
8282
warnSpy.mockRestore();
8383
});
8484

85+
it("forwards the full screen toggler texts to the error report dialog", async () => {
86+
const { openErrorReport } = renderFailedActivity({
87+
title: "Error report",
88+
fullScreenTogglerTexts: { maximize: "Vollbild anzeigen", minimize: "Vollbild verlassen" },
89+
});
90+
openErrorReport();
91+
const dialog = await screen.findByRole("dialog", { name: "Error report" });
92+
const toggler = within(dialog).getByRole("button", { name: "Vollbild anzeigen" });
93+
94+
fireEvent.click(toggler);
95+
expect(toggler).toHaveAccessibleName("Vollbild verlassen");
96+
});
97+
8598
it("forwards `aria-labelledby` to a titleless error report dialog", async () => {
8699
const { openErrorReport } = renderFailedActivity(
87100
{ "aria-labelledby": "external-report-label" },

‎src/components/Dialog/SimpleDialog.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ export interface SimpleDialogProps extends ModalProps, TestableComponent {
4545
showFullScreenToggler?: boolean;
4646
/** Starts the modal in full screen mode. The show full screen toggler will be automatically enabled. */
4747
startInFullScreenMode?: boolean;
48+
/**
49+
* Texts for the full screen toggler, used as tooltip and accessible name of the button.
50+
* `maximize` is shown while the dialog is in its normal size, `minimize` while it is in full screen mode.
51+
* Defaults to "Show in full screen" and "Exit full screen".
52+
*/
53+
fullScreenTogglerTexts?: {
54+
maximize?: string;
55+
minimize?: string;
56+
};
4857
/** Forward properties to the actions footer component. */
4958
actionsProps?: Omit<CardActionsProps, "inverseDirection">;
5059
}
@@ -69,6 +78,7 @@ export const SimpleDialog = ({
6978
headerOptions,
7079
showFullScreenToggler = false,
7180
startInFullScreenMode = false,
81+
fullScreenTogglerTexts,
7282
size,
7383
role,
7484
"aria-labelledby": ariaLabelledby,
@@ -80,7 +90,9 @@ export const SimpleDialog = ({
8090
const dialogUniqueId = React.useId().replace(/[^a-zA-Z0-9_-]/g, "");
8191
const [displayFullscreen, setDisplayFullscreen] = React.useState<boolean>(startInFullScreenMode);
8292
const showToggler = startInFullScreenMode || showFullScreenToggler;
83-
const togglerText = displayFullscreen ? "Exit full screen" : "Show in full screen";
93+
const togglerText = displayFullscreen
94+
? (fullScreenTogglerTexts?.minimize ?? "Exit full screen")
95+
: (fullScreenTogglerTexts?.maximize ?? "Show in full screen");
8496
const intentClassName = intent ? `${eccgui}-intent--${intent}` : "";
8597
const wrapperDivProps = {
8698
...modalPreventEvents,
@@ -118,6 +130,7 @@ export const SimpleDialog = ({
118130
<IconButton
119131
name={displayFullscreen ? "toggler-minimize" : "toggler-maximize"}
120132
text={togglerText}
133+
aria-label={togglerText}
121134
onClick={() => setDisplayFullscreen(!displayFullscreen)}
122135
/>
123136
)}

‎src/components/Dialog/tests/SimpleDialog.test.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ describe("SimpleDialog", () => {
224224
fireEvent.click(toggler);
225225
expect(toggler).toHaveAccessibleName("Exit full screen");
226226
});
227+
it("should use custom toggler texts if given", () => {
228+
const { toggler } = renderDialog({
229+
showFullScreenToggler: true,
230+
fullScreenTogglerTexts: { maximize: "Vollbild anzeigen", minimize: "Vollbild verlassen" },
231+
});
232+
expect(toggler).toHaveAccessibleName("Vollbild anzeigen");
233+
234+
fireEvent.click(toggler);
235+
expect(toggler).toHaveAccessibleName("Vollbild verlassen");
236+
});
227237
it("should start in full screen mode and enable the toggler", () => {
228238
const { dialog, toggler } = renderDialog({ startInFullScreenMode: true, size: "small" });
229239
expect(dialog).toHaveClass(`${dialogWrapper}--fullscreen`);

0 commit comments

Comments
 (0)