@@ -8,6 +8,7 @@ import HighchartsReact from "highcharts-react-official";
88
99import { getIsRtl , useMergeRefs , useUniqueId } from "@cloudscape-design/component-toolkit/internal" ;
1010import { isDevelopment } from "@cloudscape-design/component-toolkit/internal" ;
11+ import { useInternalI18n } from "@cloudscape-design/components/internal/do-not-use/i18n" ;
1112import Spinner from "@cloudscape-design/components/spinner" ;
1213
1314import { 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 } ,
0 commit comments