Skip to content

Commit 6de7aa7

Browse files
authored
feat(charts): allow rechart's accessibilityLayer prop (#6459)
[Recharts documentation](https://recharts.org/en-US/storybook) udner the "Accessibility" section Closes #6446
1 parent 38633a6 commit 6de7aa7

File tree

10 files changed

+22
-1
lines changed

10 files changed

+22
-1
lines changed

packages/charts/src/components/BarChart/BarChart.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ const BarChart = forwardRef<HTMLDivElement, BarChartProps>((props, ref) => {
246246
layout="vertical"
247247
data={dataset}
248248
barGap={chartConfig.barGap}
249+
accessibilityLayer={chartConfig.accessibilityLayer}
249250
className={
250251
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
251252
}

packages/charts/src/components/BulletChart/BulletChart.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ const BulletChart = forwardRef<HTMLDivElement, BulletChartProps>((props, ref) =>
290290
margin={marginChart}
291291
data={dataset}
292292
layout={layout}
293+
accessibilityLayer={chartConfig.accessibilityLayer}
293294
className={
294295
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
295296
}

packages/charts/src/components/ColumnChart/ColumnChart.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ const ColumnChart = forwardRef<HTMLDivElement, ColumnChartProps>((props, ref) =>
244244
margin={marginChart}
245245
data={dataset}
246246
barGap={chartConfig.barGap}
247+
accessibilityLayer={chartConfig.accessibilityLayer}
247248
className={
248249
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
249250
}

packages/charts/src/components/ColumnChartWithTrend/ColumnChartWithTrend.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
196196
yAxisTicksVisible: false,
197197
gridHorizontal: false,
198198
yAxisLabelsVisible: false,
199-
yAxisWidth
199+
yAxisWidth,
200+
accessibilityLayer: chartConfig.accessibilityLayer
200201
}}
201202
/>
202203
)}

packages/charts/src/components/ComposedChart/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
295295
margin={marginChart}
296296
data={dataset}
297297
layout={layout}
298+
accessibilityLayer={chartConfig.accessibilityLayer}
298299
className={
299300
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
300301
}

packages/charts/src/components/LineChart/LineChart.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
231231
margin={marginChart}
232232
data={dataset}
233233
onClick={onDataPointClickInternal}
234+
accessibilityLayer={chartConfig.accessibilityLayer}
234235
className={typeof onDataPointClick === 'function' ? 'has-click-handler' : undefined}
235236
>
236237
<CartesianGrid

packages/charts/src/components/PieChart/PieChart.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
281281
<PieChartLib
282282
onClick={onClickInternal}
283283
margin={chartConfig.margin}
284+
accessibilityLayer={chartConfig.accessibilityLayer}
284285
className={clsx(
285286
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined,
286287
classNames.piechart

packages/charts/src/components/RadarChart/RadarChart.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const RadarChart = forwardRef<HTMLDivElement, RadarChartProps>((props, ref) => {
181181
onClick={onClickInternal}
182182
data={dataset}
183183
margin={chartConfig.margin}
184+
accessibilityLayer={chartConfig.accessibilityLayer}
184185
className={typeof onDataPointClick === 'function' ? 'has-click-handler' : undefined}
185186
>
186187
<PolarGrid gridType={chartConfig.polarGridType} />

packages/charts/src/components/ScatterChart/ScatterChart.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ const ScatterChart = forwardRef<HTMLDivElement, ScatterChartProps>((props, ref)
231231
<ScatterChartLib
232232
onClick={onClickInternal}
233233
margin={marginChart}
234+
accessibilityLayer={chartConfig.accessibilityLayer}
234235
className={typeof onDataPointClick === 'function' ? 'has-click-handler' : undefined}
235236
>
236237
<CartesianGrid

packages/charts/src/interfaces/IChartBaseProps.ts

+12
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface IChartBaseProps<T = ICartesianChartConfig> extends Omit<CommonP
6868
* - `legendPosition`: Vertical position of the legend. Can be one of the following: `"top"`,`"middle"`, `"bottom"` (`"middle"` is not supported for: ColumnChartWithTrend, DonutChart, PieChart)
6969
* - `legendHorizontalAlign`: Alignment of the legend. Can be one of the following: `"left"`, `"center"`, `"right"`
7070
* - `resizeDebounce`: Number that sets the amount of delay time the chart waits when resizing.
71+
* - `accessibilityLayer`: Experimental property to improve accessibility. Not supported by all charts and configurations!
7172
*
7273
* Please note that depending on the chart type, the `chartConfig` prop may accept more properties.
7374
*/
@@ -93,6 +94,17 @@ export interface IChartBaseProps<T = ICartesianChartConfig> extends Omit<CommonP
9394
* Number that sets the amount of delay time the chart waits when resizing.
9495
*/
9596
resizeDebounce?: number;
97+
/**
98+
* __Experimental!__
99+
*
100+
* Apply an accessibility layer on the chart, i.a. allowing users to focus and navigate the chart via the arrow keys.
101+
*
102+
* __Note:__ Currently, this feature only supports categorical and horizontal charts with tooltips!
103+
* For more details, please refer to the [Recharts documentation](https://recharts.org/en-US/storybook) under the "Accessibility" section.
104+
*
105+
* @experimental
106+
*/
107+
accessibilityLayer?: boolean;
96108
};
97109
/**
98110
* Defines the configuration object for the internally used `recharts` Tooltip popover that is displayed when hovering over data points.

0 commit comments

Comments
 (0)