read willBeHidden from hiddenLabels in handleLegendClick
Address Greptile P2 review on PR #4259. willBeHidden was derived from !ds.hidden, but ds.hidden can be set by the focusLabel pass too, so the dataset flag is not a faithful read of the controlled hidden state. In a chart that uses both focusLabel and hiddenLabels at once, the callback could fire with a misleading toggle direction. Read directly from hiddenLabels instead, with optional chaining so the new path is a no-op when hiddenLabels is not provided. Behavior is unchanged for EventsChart (which does not use focusLabel today) but the controlled state is now the single source of truth.
This commit is contained in:
@@ -70,7 +70,7 @@ export function Chart({
|
||||
// and let the parent push a new hiddenLabels set on the next render.
|
||||
const { datasetIndex } = item;
|
||||
const ds = chart.current.data.datasets[datasetIndex];
|
||||
onLegendClick(ds.label, !ds.hidden);
|
||||
onLegendClick(ds.label, !hiddenLabels?.has(ds.label));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user