react-drag-to-select icon indicating copy to clipboard operation
react-drag-to-select copied to clipboard

Why is the rect argument needed in the getPointFromEvent function?

Open billy5982 opened this issue 1 year ago • 7 comments

In all cases where the getPointFromEvent function is used, rect is passed as getParentBoundingClientRect(). Is there any specific reason for explicitly providing rect as an argument when it's always the same value?

https://github.com/AirLabsTeam/react-drag-to-select/blob/7ae9ada562d4ebfa288a0079929dd0993b97e2ff/src/hooks/useSelectionLogic.ts#L98

billy5982 avatar Sep 17 '24 15:09 billy5982

It doesn't have to be the same - what if container was resized?

tomaszczura avatar Sep 17 '24 15:09 tomaszczura

Oh, I wasn't aware of that! My mistake! Thank you for your accurate and kind reply! I was able to think again. Thank you!

billy5982 avatar Sep 17 '24 16:09 billy5982

@tomaszczura I'm so sorry. Can I ask you one more question because there's something I don't understand?? Is it different from declaring and using 'rect = containerRef.current?.getParentBoundingClientRect();' instead of 'rect' factor in 'getPointFromEvent' function?

billy5982 avatar Sep 17 '24 16:09 billy5982

That's a good question. Now I see that getPointFromEvent is called with rect param only in one place, and containerRef.current?.getParentBoundingClientRect(); is passed there. So this param could be removed, since it is not really used

tomaszczura avatar Sep 17 '24 16:09 tomaszczura

Thank you so much for the good response! Can I register 'pr' for that? @tomaszczura

billy5982 avatar Sep 18 '24 04:09 billy5982

Sure, any help is appreciated ;)

tomaszczura avatar Sep 18 '24 06:09 tomaszczura

@tomaszczura Thank you so much for your kind reply and confirmation.

billy5982 avatar Sep 18 '24 13:09 billy5982