diff --git a/src/chart.tsx b/src/chart.tsx index 08df13418..daa7c8428 100644 --- a/src/chart.tsx +++ b/src/chart.tsx @@ -26,6 +26,7 @@ function ChartComponent< options, plugins = [], fallbackContent, + updateMode, ...props }: ChartProps, ref: ForwardedRef> @@ -82,9 +83,9 @@ function ChartComponent< destroyChart(); setTimeout(renderChart); } else { - chartRef.current.update(); + chartRef.current.update(updateMode); } - }, [redraw, options, data.labels, data.datasets]); + }, [redraw, options, data.labels, data.datasets, updateMode]); useEffect(() => { renderChart(); diff --git a/src/types.ts b/src/types.ts index 36f9eeeb2..cefa693d2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,6 +6,7 @@ import type { ChartOptions, DefaultDataPoint, Plugin, + UpdateMode, } from 'chart.js'; export type ForwardedRef = @@ -56,6 +57,11 @@ export interface ChartProps< * @todo Replace with `children` prop. */ fallbackContent?: ReactNode; + /** + * A mode string to indicate transition configuration should be used. + * @see https://www.chartjs.org/docs/latest/developers/api.html#update-mode + */ + updateMode?: UpdateMode; } /** diff --git a/test/chart.test.tsx b/test/chart.test.tsx index e28c910d0..646f35e68 100644 --- a/test/chart.test.tsx +++ b/test/chart.test.tsx @@ -386,4 +386,34 @@ describe('', () => { expect(prevDataset1).toBe(nextDataset1); expect(prevDataset2).toBe(nextDataset2); }); + + it('should pass updateMode prop to update method', () => { + const newData = { + labels: ['purple', 'pink'], + datasets: [{ label: 'new-colors', data: [1, 10] }], + }; + + const { rerender } = render( + + ); + + rerender( + + ); + + expect(update).toHaveBeenCalledTimes(1); + expect(update).toBeCalledWith('active'); + }); });