Skip to content

Commit 69fba1a

Browse files
committed
ensure all accessible labels are supported via our i18n
1 parent 28fe3cc commit 69fba1a

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

src/__tests__/__snapshots__/documenter.test.ts.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ Supported Highcharts versions:
128128
"inlineType": {
129129
"name": "BaseI18nStrings",
130130
"properties": [
131+
{
132+
"name": "chartAccessibleDescription",
133+
"optional": true,
134+
"type": "string",
135+
},
131136
{
132137
"name": "detailPopoverDismissAriaLabel",
133138
"optional": true,
@@ -163,6 +168,21 @@ Supported Highcharts versions:
163168
"optional": true,
164169
"type": "string",
165170
},
171+
{
172+
"name": "seriesFilterSelectedAriaLabel",
173+
"optional": true,
174+
"type": "string",
175+
},
176+
{
177+
"name": "xAxisAccessibleDescription",
178+
"optional": true,
179+
"type": "string",
180+
},
181+
{
182+
"name": "yAxisAccessibleDescription",
183+
"optional": true,
184+
"type": "string",
185+
},
166186
],
167187
"type": "object",
168188
},
@@ -619,6 +639,11 @@ Supported Highcharts versions:
619639
"inlineType": {
620640
"name": "BaseI18nStrings",
621641
"properties": [
642+
{
643+
"name": "chartAccessibleDescription",
644+
"optional": true,
645+
"type": "string",
646+
},
622647
{
623648
"name": "detailPopoverDismissAriaLabel",
624649
"optional": true,
@@ -654,6 +679,21 @@ Supported Highcharts versions:
654679
"optional": true,
655680
"type": "string",
656681
},
682+
{
683+
"name": "seriesFilterSelectedAriaLabel",
684+
"optional": true,
685+
"type": "string",
686+
},
687+
{
688+
"name": "xAxisAccessibleDescription",
689+
"optional": true,
690+
"type": "string",
691+
},
692+
{
693+
"name": "yAxisAccessibleDescription",
694+
"optional": true,
695+
"type": "string",
696+
},
657697
],
658698
"type": "object",
659699
},

src/core/chart-core.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import HighchartsReact from "highcharts-react-official";
88

99
import { getIsRtl, useMergeRefs, useUniqueId } from "@cloudscape-design/component-toolkit/internal";
1010
import { isDevelopment } from "@cloudscape-design/component-toolkit/internal";
11+
import { useInternalI18n } from "@cloudscape-design/components/internal/do-not-use/i18n";
1112
import Spinner from "@cloudscape-design/components/spinner";
1213

1314
import { getDataAttributes } from "../internal/base-component/get-data-attributes";
@@ -64,6 +65,7 @@ export function InternalCoreChart({
6465
...rest
6566
}: CoreChartProps & InternalBaseComponentProps) {
6667
const highcharts = rest.highcharts as null | typeof Highcharts;
68+
const i18n = useInternalI18n("[charts]");
6769

6870
const settings = {
6971
chartId: useUniqueId(),
@@ -107,6 +109,15 @@ export function InternalCoreChart({
107109
);
108110
}
109111

112+
const aria = {
113+
chartLabel: ariaLabel,
114+
chartDescription: ariaDescription,
115+
// We reuse existing translations as passing for now, but it is possible to introduce new i18n strings that
116+
// are parametrized with axes names, and more.
117+
chartContainerLabel: i18n("i18nStrings.chartAriaRoleDescription", i18nStrings?.chartAccessibleDescription),
118+
chartXAxisLabel: i18n("i18nStrings.xAxisAriaRoleDescription", i18nStrings?.xAxisAccessibleDescription),
119+
chartYAxisLabel: i18n("i18nStrings.yAxisAriaRoleDescription", i18nStrings?.yAxisAccessibleDescription),
120+
};
110121
const apiOptions = api.getOptions();
111122
const inverted = !!options.chart?.inverted;
112123
const isRtl = () => getIsRtl(rootRef?.current);
@@ -168,11 +179,28 @@ export function InternalCoreChart({
168179
legend: options.legend ?? { enabled: false },
169180
lang: {
170181
...options.lang,
171-
// The default chart title is disabled by default to prevent the default "Chart" in the screen-reader detail.
172-
accessibility: { defaultChartTitle: "", chartContainerLabel: ariaLabel, ...options.lang?.accessibility },
182+
accessibility: {
183+
// The default chart title is disabled by default to prevent the default "Chart" in the screen-reader detail.
184+
defaultChartTitle: "",
185+
chartContainerLabel: aria.chartLabel,
186+
svgContainerLabel: aria.chartContainerLabel,
187+
// We used {names[0]} to inject the axis title, see: https://api.highcharts.com/highcharts/lang.accessibility.axis.xAxisDescriptionSingular.
188+
axis: {
189+
xAxisDescriptionSingular: aria.chartXAxisLabel ? `${aria.chartXAxisLabel}, {names[0]}` : undefined,
190+
yAxisDescriptionSingular: aria.chartYAxisLabel ? `${aria.chartYAxisLabel}, {names[0]}` : undefined,
191+
},
192+
...options.lang?.accessibility,
193+
},
173194
},
174195
accessibility: {
175-
description: ariaDescription,
196+
description: aria.chartDescription,
197+
screenReaderSection: {
198+
// We use custom before-message to remove detail that are currently not supported with our i18n.
199+
// See: https://api.highcharts.com/highcharts/accessibility.screenReaderSection.beforeChartFormat.
200+
beforeChartFormat: "<div>{xAxisDescription}</div><div>{yAxisDescription}</div>",
201+
// We hide after message as it is currently not supported with our i18n.
202+
afterChartFormat: "",
203+
},
176204
...options.accessibility,
177205
// Highcharts keyboard navigation is disabled by default in favour of the custom Cloudscape navigation.
178206
keyboardNavigation: options.accessibility?.keyboardNavigation ?? { enabled: !keyboardNavigation },

src/core/interfaces.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,28 @@ export interface BaseNoDataOptions {
101101
}
102102

103103
export interface BaseI18nStrings {
104+
/** Text that is displayed when the chart is loading, i.e. when `noData.statusType` is set to `"loading". */
104105
loadingText?: string;
106+
/** Text that is displayed when the chart is in error state, i.e. when `noData.statusType` is set to `"error". */
105107
errorText?: string;
108+
/** Text for the recovery button that is displayed next to the error text. */
106109
recoveryText?: string;
110+
/** Visible label of the default series filter */
107111
seriesFilterLabel?: string;
112+
/** Placeholder text of the default series filter */
108113
seriesFilterPlaceholder?: string;
114+
/** ARIA label of the default series filter which is appended to any option that is selected */
109115
seriesFilterSelectedAriaLabel?: string;
116+
/** ARIA label that is associated with the legend in case there is no visible `legendTitle` defined */
110117
legendAriaLabel?: string;
118+
/** ARIA label for details popover dismiss button */
111119
detailPopoverDismissAriaLabel?: string;
120+
/** Generalized accessible description of the chart, e.g. "line chart" */
121+
chartAccessibleDescription?: string;
122+
/** Generalized accessible description of the x axis, e.g. "x axis" */
123+
xAxisAccessibleDescription?: string;
124+
/** Generalized accessible description of the y axis, e.g. "y axis" */
125+
yAxisAccessibleDescription?: string;
112126
}
113127

114128
export interface BaseFilterOptions {

0 commit comments

Comments
 (0)