Skip to content

[charts] Support module augmentation for slots #14063

@flaviendelangle

Description

@flaviendelangle

All the slots in @mui/x-charts and @mui/x-charts-pro packages should support module augmentation.
This allows to pass custom props to your slots without casting the types.

Here is how it works on the data grid:

declare module '@mui/x-data-grid' {
  interface ToolbarPropsOverrides {
    name: string;
    setName: (name: string) => void;
  }
}

You can then use your custom slot without any type casting:

function CustomToolbar({ name, setName }: PropsFromSlot<GridSlots['toolbar']>) {
  return <input value={name} onChange={(event) => setName(event.target.value)} />;
}

function MyApp() {
  const [name, setName] = React.useState('');
  return (
    <DataGrid
      rows={[]}
      columns={[]}
      slots={{ toolbar: CustomToolbar }}
      slotProps={{
        toolbar: { name, setName },
      }}
    />
  );
}

Search keywords:

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: chartsChanges related to the charts.type: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.typescriptwaiting for 👍Waiting for upvotes. Open for community feedback and needs more interest to be worked on.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions