Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

legend onLeave not triggered with scroll

Open Mottoweb opened this issue 3 years ago • 2 comments

Expected behavior

Scroll down the page while hovering over tooltip item should trigger onLeave callback

Current behavior

Scrolling down the page while hovering over tooltip does not trigger onLeave

Reproducible sample

https://codesandbox.io/s/chart-js-2-forked-zr1izh?file=/src/App.js

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

3.5.1

Browser name and version

No response

Link to your project

No response

Mottoweb avatar May 27 '22 11:05 Mottoweb

Happening because of this line: https://github.com/chartjs/Chart.js/blob/1a1151b122c481d814850a001de1b2d0468fce4e/src/plugins/plugin.legend.js#L527

Whenn scrolling there is no mousemove or mouseout event.

Don't think listening to the scroll event will solve this issue since the scroll event does not pass the mouse x and y. Don't know if this can be easily solvable since the scroll event does not seem to have any offset if I log it so you cant keep the last position in memory and calculate the mouse position.

LeeLenaleee avatar May 27 '22 14:05 LeeLenaleee

@LeeLenaleee yes I understand this absolutely, currently, I just have to manually trigger onLeave on scroll.

One possible solution I can think of would be to save the last mouse position when onHover happens, then listen to scroll and offset the mouse position based on the scroll and then trigger onLeave based on that position.

Found an example here https://ogeek.cn/qa/?qa=632130/

Mottoweb avatar May 27 '22 14:05 Mottoweb