[charts] Support module augmentation for slots#22519
Conversation
Deploy preview
Bundle size
PerformanceTotal duration: 934.17 ms +12.41 ms(+1.3%) | Renders: 30 (+0) | Paint: 1,304.87 ms +18.41 ms(+1.4%) No significant changes — details Check out the code infra dashboard for more information about this PR. |
|
@alexfauquette @JCQuintas (Picked this issue from project dashboard) Before working on other components, i'd like to know, if you are aligned on the direction this PR is taking. I don't see any issue in CI w.r.t this new test, module augmentation is working fine https://github.com/mui/mui-x/pull/22519/changes#diff-56cd55c5e986a1577a4b59332231607ec9b36bb4346fd931cfd1997b400db60f |
| import { type ChartsTooltipProps } from './ChartsTooltip'; | ||
| import { type TriggerOptions } from './utils'; | ||
|
|
||
| export interface TooltipPropsOverrides {} |
There was a problem hiding this comment.
micht be easier if like in the data grid we define all those XxxPropsOverrides in a dedicated filemodels/chartsSlotsComponentsProps.ts to be sure we don't have duplicated interfaces
There was a problem hiding this comment.
Pull request overview
This PR adds Data Grid–style module augmentation support for Charts slots across Community/Pro/Premium packages, enabling consumers to extend slot prop types via ${SlotName}PropsOverrides interfaces without casting.
Changes:
- Introduces exported empty
*PropsOverridesinterfaces (Community/Pro/Premium) and threads them throughslots/slotPropstypings. - Fixes a few charts that re-declared shared slots (notably
tooltip) so overrides aren’t dropped. - Adds type-only spec files to exercise override augmentation, and documents the pattern in Charts docs and common concepts.
Reviewed changes
Copilot reviewed 41 out of 41 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/x-charts.exports.json | Exposes new Community *PropsOverrides interfaces in the package exports metadata. |
| scripts/x-charts-pro.exports.json | Exposes new Pro *PropsOverrides interfaces in the package exports metadata. |
| scripts/x-charts-premium.exports.json | Exposes new Premium *PropsOverrides interfaces in the package exports metadata. |
| packages/x-charts/src/Toolbar/Toolbar.types.ts | Threads ToolbarPropsOverrides into toolbar slot + slotProps typing. |
| packages/x-charts/src/tests/slotPropsOverrides.spec.tsx | Adds Community type-only specs validating augmentation across representative charts/slots. |
| packages/x-charts/src/ScatterChart/ScatterPlot.tsx | Adds ScatterPropsOverrides to the scatter slot typing. |
| packages/x-charts/src/ScatterChart/ScatterMarker.types.ts | Adds MarkerPropsOverrides to the marker slot typing. |
| packages/x-charts/src/ScatterChart/ScatterChart.tsx | Ensures scatter chart tooltip slotProps includes TooltipPropsOverrides. |
| packages/x-charts/src/PieChart/PieArcPlot.tsx | Adds PieArcPropsOverrides to the pieArc slot typing. |
| packages/x-charts/src/PieChart/PieArcLabelPlot.tsx | Adds PieArcLabelPropsOverrides to the pieArcLabel slot typing. |
| packages/x-charts/src/models/slots/chartsBaseSlots.ts | Adds base-slot override interfaces to base slot component prop types. |
| packages/x-charts/src/models/index.ts | Re-exports chartsSlotsComponentsProps from @mui/x-charts/models. |
| packages/x-charts/src/models/chartsSlotsComponentsProps.ts | Introduces Community *PropsOverrides augmentation interfaces. |
| packages/x-charts/src/models/axis.ts | Adds axis-related override interfaces to axis slot + slotProps typings. |
| packages/x-charts/src/LineChart/MarkPlot.tsx | Adds MarkPropsOverrides to the mark slot typing. |
| packages/x-charts/src/LineChart/LineHighlightPlot.tsx | Adds LineHighlightPropsOverrides to the lineHighlight slot typing. |
| packages/x-charts/src/LineChart/LineElement.tsx | Adds LinePropsOverrides to the line slot typing. |
| packages/x-charts/src/LineChart/AreaElement.tsx | Adds AreaPropsOverrides to the area slot typing. |
| packages/x-charts/src/ChartsTooltip/ChartTooltip.types.ts | Adds TooltipPropsOverrides to tooltip slot + slotProps typing. |
| packages/x-charts/src/ChartsOverlay/ChartsOverlay.tsx | Adds overlay override interfaces to overlay slot + slotProps typing. |
| packages/x-charts/src/ChartsLegend/chartsLegend.types.ts | Adds LegendPropsOverrides to legend slot + slotProps typing. |
| packages/x-charts/src/BarChart/BarLabel/BarLabelItem.tsx | Adds BarLabelPropsOverrides to barLabel slot typing. |
| packages/x-charts/src/BarChart/BarElement.tsx | Adds BarPropsOverrides to bar slot typing. |
| packages/x-charts-pro/src/tests/slotPropsOverrides.spec.tsx | Adds Pro type-only specs validating Pro-only overrides and shared overrides usage. |
| packages/x-charts-pro/src/ScatterChartPro/ScatterChartPro.tsx | Ensures tooltip slotProps includes TooltipPropsOverrides for ScatterChartPro. |
| packages/x-charts-pro/src/models/index.ts | Re-exports Pro override interfaces from @mui/x-charts-pro/models. |
| packages/x-charts-pro/src/models/chartsSlotsComponentsPropsPro.ts | Introduces Pro-only *PropsOverrides augmentation interfaces. |
| packages/x-charts-pro/src/internals/slots/chartsIconSlots.ts | Adds override interfaces to Pro toolbar icon slot prop types. |
| packages/x-charts-pro/src/internals/slots/chartsBaseSlots.ts | Adds override interfaces to Pro base slot prop types. |
| packages/x-charts-pro/src/Heatmap/HeatmapTooltip/HeatmapTooltip.types.ts | Adds TooltipPropsOverrides to Heatmap tooltip slot typing. |
| packages/x-charts-pro/src/Heatmap/HeatmapItem.tsx | Adds CellPropsOverrides to Heatmap cell slot typing and usage. |
| packages/x-charts-pro/src/Heatmap/Heatmap.tsx | Adds TooltipPropsOverrides to Heatmap tooltip slot typing. |
| packages/x-charts-pro/src/FunnelChart/funnelPlotSlots.types.ts | Adds override interfaces to funnel section/label slot typings. |
| packages/x-charts-pro/src/ChartsToolbarPro/Toolbar.types.ts | Threads shared ToolbarPropsOverrides into pro toolbar slot typings. |
| packages/x-charts-premium/src/tests/slotPropsOverrides.spec.tsx | Adds Premium type-only specs validating Premium-only and shared override usage. |
| packages/x-charts-premium/src/ScatterChartPremium/ScatterChartPremium.tsx | Ensures tooltip slotProps includes TooltipPropsOverrides for ScatterChartPremium. |
| packages/x-charts-premium/src/RadialLineChart/RadialLineHighlightPlot.tsx | Adds RadialLineHighlightPropsOverrides to the premium slot typing. |
| packages/x-charts-premium/src/models/index.ts | Re-exports Premium override interfaces from @mui/x-charts-premium/models. |
| packages/x-charts-premium/src/models/chartsSlotsComponentsPropsPremium.ts | Introduces Premium-only RadialLineHighlightPropsOverrides interface. |
| docs/data/common-concepts/custom-components/custom-components.md | Updates common “custom components” docs to include Charts module augmentation usage. |
| docs/data/charts/components/components.md | Adds a “Custom slot props with TypeScript” section documenting the override pattern. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { ChartsSurface } from '@mui/x-charts/ChartsSurface'; | ||
| import { ChartsAxisHighlight } from '@mui/x-charts/ChartsAxisHighlight'; | ||
| import { ChartsTooltip, type ChartsTooltipProps } from '@mui/x-charts/ChartsTooltip'; | ||
| import type { TooltipPropsOverrides } from '@mui/x-charts/models'; |
| type XAxis, | ||
| type YAxis, | ||
| } from '@mui/x-charts/internals'; | ||
| import type { TooltipPropsOverrides } from '@mui/x-charts/models'; |
| type ChartsTooltipContainerProps, | ||
| type ChartsTooltipClasses, | ||
| } from '@mui/x-charts/ChartsTooltip'; | ||
| import type { TooltipPropsOverrides } from '@mui/x-charts/models'; |
| @@ -1,16 +1,17 @@ | |||
| import type * as React from 'react'; | |||
| import type { ToolbarPropsOverrides } from '@mui/x-charts/models'; | |||
| import { ChartsAxisHighlight } from '@mui/x-charts/ChartsAxisHighlight'; | ||
| import { ChartsLegend } from '@mui/x-charts/ChartsLegend'; | ||
| import { ChartsTooltip, type ChartsTooltipProps } from '@mui/x-charts/ChartsTooltip'; | ||
| import type { TooltipPropsOverrides } from '@mui/x-charts/models'; |
| declare module '@mui/x-charts/models' { | ||
| interface TooltipPropsOverrides { | ||
| heatmapTooltipExtra?: string; | ||
| } | ||
| } | ||
|
|
||
| declare module '@mui/x-charts-pro/models' { | ||
| // Pro base slots | ||
| interface BaseDividerPropsOverrides { |
| declare module '@mui/x-charts/models' { | ||
| interface TooltipPropsOverrides { | ||
| scatterPremiumTooltipExtra?: string; | ||
| } | ||
| } | ||
|
|
||
| declare module '@mui/x-charts-premium/models' { | ||
| interface RadialLineHighlightPropsOverrides { | ||
| customRadialLineHighlightProp?: string; |
…into charts-custom-slots
| /** | ||
| * Note: MUI's `ToggleButton` has an incompatible `href` prop, so it must be cast: | ||
| * `ToggleButton as unknown as React.ComponentType<ChartBaseToggleButtonProps>`. | ||
| */ |
| } | ||
| export interface BarElementSlotProps { | ||
| bar?: SlotComponentPropsFromProps<BarProps, {}, BarElementOwnerState>; | ||
| bar?: SlotComponentPropsFromProps<BarProps & BarPropsOverrides, {}, BarElementOwnerState>; |
| BarLabelProps & BarLabelPropsOverrides, | ||
| {}, |
| AnimatedLineProps & LinePropsOverrides, | ||
| {}, |
| AnimatedAreaProps & AreaPropsOverrides, | ||
| {}, |
| LineHighlightElementProps & LineHighlightPropsOverrides, | ||
| {}, |
| CommonOverlayProps & LoadingOverlayPropsOverrides, | ||
| {}, | ||
| {} | ||
| >; | ||
| noDataOverlay?: SlotComponentPropsFromProps< | ||
| CommonOverlayProps & NoDataOverlayPropsOverrides, | ||
| {}, |
| RadialLineHighlightElementProps & RadialLineHighlightPropsOverrides, | ||
| {}, |
alexfauquette
left a comment
There was a problem hiding this comment.
Over all look nice. I will give a deeper look tomorow
| :::success | ||
| This section focuses on module augmentation. | ||
|
|
||
| See [Custom slots and subcomponents—Usage with TypeScript](/x/common-concepts/custom-components/#usage-with-typescript) if you don't want to use this approach. |
There was a problem hiding this comment.
I don't get this comment. It feels like this page is a workaround. Whereas it's just the same content but for charts specificly
There was a problem hiding this comment.
By the way make me wonder if we should also export a PropsFromSlot generic helper
There was a problem hiding this comment.
By the way make me wonder if we should also export a
PropsFromSlotgeneric helper
I think it's already exported here 🤔
https://github.com/mui/mui-x/blob/master/packages/x-charts/src/models/index.ts#L22
I don't get this comment. It feels like this page is a workaround. Whereas it's just the same content but for charts specificly
Removed, also removed block from this suggestion #22519 (comment)
|
|
||
| ```ts | ||
| declare module '@mui/x-charts' { | ||
| interface TooltipPropsOverrides { | ||
| label: string; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ```tsx | ||
| function CustomTooltip({ label }: PropsFromSlot<LineChartSlots['tooltip']>) { | ||
| return <div>{label}</div>; | ||
| } | ||
|
|
||
| function MyApp() { | ||
| return ( | ||
| <LineChart | ||
| series={[{ data: [1, 2, 3] }]} | ||
| slots={{ tooltip: CustomTooltip }} | ||
| slotProps={{ tooltip: { label: 'Value' } }} | ||
| /> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| See [Data Grid - Custom slots and subcomponents—Custom slot props with TypeScript](/x/react-data-grid/components/#custom-slot-props-with-typescript) or [Charts - Custom slot props with TypeScript](/x/react-charts/components/#custom-slot-props-with-typescript) for more details. |
There was a problem hiding this comment.
Not sure it's usefull to have a code sample per library
| ```ts | |
| declare module '@mui/x-charts' { | |
| interface TooltipPropsOverrides { | |
| label: string; | |
| } | |
| } | |
| ``` | |
| ```tsx | |
| function CustomTooltip({ label }: PropsFromSlot<LineChartSlots['tooltip']>) { | |
| return <div>{label}</div>; | |
| } | |
| function MyApp() { | |
| return ( | |
| <LineChart | |
| series={[{ data: [1, 2, 3] }]} | |
| slots={{ tooltip: CustomTooltip }} | |
| slotProps={{ tooltip: { label: 'Value' } }} | |
| /> | |
| ); | |
| } | |
| ``` | |
| See [Data Grid - Custom slots and subcomponents—Custom slot props with TypeScript](/x/react-data-grid/components/#custom-slot-props-with-typescript) or [Charts - Custom slot props with TypeScript](/x/react-charts/components/#custom-slot-props-with-typescript) for more details. | |
| For more details, see: | |
| - [Data Grid - Custom slots and subcomponents—Custom slot props with TypeScript](/x/react-data-grid/components/#custom-slot-props-with-typescript) | |
| - [Charts - Custom slot props with TypeScript](/x/react-charts/components/#custom-slot-props-with-typescript) for more details. |
closes #14063
preview: https://deploy-preview-22519--material-ui-x.netlify.app/x/react-charts/components/#custom-slot-props-with-typescript
Add module augmentation support for all slots in Charts
Mirrors the data-grid pattern: every slot exposes an empty
${SlotName}PropsOverridesinterface that consumers extend viadeclare module '...'.Augmented props flow through
PropsFromSlot<ChartSlots['name']>without casts.Coverage
baseButton,baseIconButton,baseToggleButton,baseToggleButtonGroupaxisLine,axisTick,axisTickLabel,axisLabel,xAxis,yAxisBarChartbar,barLabelLineChartline,area,mark,lineHighlightPieChartpieArc,pieArcLabelScatterChartscatter,markertooltip,legend,toolbar,loadingOverlay,noDataOverlaybaseDivider,baseMenuItem,baseMenuList,basePopper,baseTooltip,zoomInIcon,zoomOutIcon,exportIconHeatmapcellFunnelChartfunnelSection,funnelSectionLabelRadialLineChartradialLineHighlightWhere overrides live
packages/x-charts/src/models/chartsSlotsComponentsProps.tspackages/x-charts-pro/src/models/chartsSlotsComponentsPropsPro.tspackages/x-charts-premium/src/models/chartsSlotsComponentsPropsPremium.tsNotes
Augment the package where the interface is declared (not where the chart is imported from).
For example, use:
for shared slots like
tooltip, even when using<RadialLineChart />.Fixed re-declared tooltip slots that silently dropped the override:
ScatterChartScatterChartProScatterChartPremiumHeatmapNormalized
markerandfunnelSection*slot props to:for API consistency.
Tests
Type-only
*.spec.tsxspecs in each package exercise every override via real JSX (slots+slotProps) on a representative chart.Docs
docs/data/charts/components/components.mdgains a "Custom slot props with TypeScript" section with Community / Pro / Premium tabs, mirroring Data Grid.