From e3475e061263d571e5a865523f0c4a643568892f Mon Sep 17 00:00:00 2001 From: vbersch Date: Tue, 19 May 2020 08:50:03 +0200 Subject: [PATCH] fix(Charts): fix onDataPointClick event not firing or firing for wrong segment on Donut/PieChart (#524) --- .../charts/src/components/PieChart/PieChart.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/charts/src/components/PieChart/PieChart.tsx b/packages/charts/src/components/PieChart/PieChart.tsx index 2bce5a5df24..89d3a9cde91 100644 --- a/packages/charts/src/components/PieChart/PieChart.tsx +++ b/packages/charts/src/components/PieChart/PieChart.tsx @@ -116,15 +116,15 @@ const PieChart: FC = forwardRef((props: PieChartProps, ref: Ref measure.accessor); const onDataPointClickInternal = useCallback( - (payload, event) => { - if (payload && payload?.activePayload && onDataPointClick) { + (payload, dataIndex, event) => { + if (payload && payload && typeof onDataPointClick === 'function') { onDataPointClick( enrichEventWithDetails(event, { - value: payload.activePayload[0].value, - dataKey: payload.activePayload[0].dataKey, - name: payload.activePayload[0].payload.name, - payload: payload.activePayload[0].payload, - dataIndex: payload.activeTooltipIndex + value: payload.value, + dataKey: payload.tooltipPayload?.[0]?.dataKey, + name: payload.name, + payload: payload.payload, + dataIndex }) ); } @@ -145,11 +145,11 @@ const PieChart: FC = forwardRef((props: PieChartProps, ref: Ref