recharts / recharts

Redefined chart library built with React and D3
http://recharts.org
MIT License
24.16k stars 1.72k forks source link

I would like `onClick` function in XAxis to include full `React.MouseEvent` event #2674

Open zepplock opened 3 years ago

zepplock commented 3 years ago

What problem does this feature solve?

Right now, there's no way to tell if click on XAxis (or any axis) had any modifiers (shift/ctrl/alt), whereas the full MouseEvent has e.altKey evailable. In fact this might be a bug since typscript definition specifies a full React.MouseEvent for onClick

What does the proposed API look like?

This is not changing an API but rather pass a full MouseEvent vs a truncated one

zepplock commented 3 years ago

This is also similar but not exact issue: https://github.com/recharts/recharts/issues/1946

zepplock commented 3 years ago

Hello, any update?

ckifer commented 1 year ago

Hi @zepplock

The ability to add the onClick property is a side effect of some interesting type extensions in the library.

Here are the props for XAxis. Because this extends SVGProps...onClick and many others get added to the types here.

Barring that you can access the original event with a different parameter because the events get adapted to add information to them/return different params

 onClick={(xAxisInfo, index, originalEvent) => {
     console.log(xAxisInfo, index, originalEvent);
}}

originalEvent should be what you want as per these two functions

ckifer commented 1 year ago

Labeling this as a typescript enhancement because currently the assumed type is incorrect as per the returned params in the onClick function