From 9b497b78cf820f7af54f26cb10df855c4c54eaa3 Mon Sep 17 00:00:00 2001 From: Viktor Bersch Date: Tue, 19 May 2020 08:17:09 +0200 Subject: [PATCH] fix(Charts): fix onDataPointClick event not firing or firing for wrong segment on Donut/Piechart --- .../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 0b43f4548f4..00600421f04 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