Repository navigation
[charts][docs] Document click listener for scatter composition - #22809
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Scatter chart documentation to clarify how onItemClick is wired when using the Scatter chart in a composed setup (e.g. ChartsDataProvider + ScatterPlot), addressing the need to document the special click-listener behavior.
Changes:
- Adds a cross-reference from the “Click event” section to composition-specific click handling guidance.
- Introduces a new “Handling clicks” subsection under “Composition” describing where to attach
onItemClickdepending on hit-area behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <ChartsDataProvider onItemClick={handleItemClick}>{/* ... */}</ChartsDataProvider> | ||
| ``` | ||
|
|
||
| When `disableHitArea` is `true` (with the default `svg-single` renderer), the user must click directly on a marker, so pass `onItemClick` to `ScatterPlot` instead. |
Deploy previewBundle size
PerformanceTotal duration: 2,249.82 ms +244.31 ms(+12.2%) | Renders: 67 (+0)
…and 8 more (+13 within noise) — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
|
@alexfauquette I suppose we will leverage the "calculate position" method more often (webgl, new chart types, etc), should we look at reworking the api instead? Else we will be in this state where "if this, then that, if that, then this" |
Looks like we can keep the API as it is. and do not document the We could remove it in the v10 for API simplification |
|
| /** | ||
| * Callback fired when a marker is clicked directly and `disableHitArea` is `true`. | ||
| * When `disableHitArea` is `false`, use `onItemClick` on the chart container to handle closest-point clicks. | ||
| * @param {MouseEvent} event Mouse event recorded on the `<svg/>` element. | ||
| * @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier. |
There was a problem hiding this comment.
That's true but at the ScatterChart level.
For the props of the ScatterPlot, the onItemClick will be trigger independently from the disableHitArea value.
This logic is just in the useScatterChartProps that
- if
disableHitArea=true=> theonItemClickis propagated to the ScatterPlot - if
disableHitArea=false=> theonItemClickis propagated to the DataProvider
alexfauquette
left a comment
There was a problem hiding this comment.
While reviewing I noticed we already have a docs section about it 🫣
https://mui.com/x/react-charts/scatter/#click-event
So I just added some additoinal option to play with it
…2809) Co-authored-by: alex <alex.fauquette@gmail.com>

closes #11933
In addition to this PR change, should we also disallow passing
onItemClickonChartsDataProviderwhendisableHitAreais true through typescript?preview: https://deploy-preview-22809--material-ui-x.netlify.app/x/react-charts/scatter/#handling-clicks
Preview: https://deploy-preview-22809--material-ui-x.netlify.app/x/react-charts/scatter/