AirLabsTeam / react-drag-to-select

A react library which adds drag to select to your app
https://airlabsteam.github.io/react-drag-to-select
MIT License
155 stars 22 forks source link

Why is the rect argument needed in the getPointFromEvent function? #48

Open billy5982 opened 1 day ago

billy5982 commented 1 day ago

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

tomaszczura commented 1 day ago

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

billy5982 commented 1 day ago

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 commented 1 day ago

@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?

tomaszczura commented 1 day ago

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

billy5982 commented 1 day ago

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

tomaszczura commented 1 day ago

Sure, any help is appreciated ;)

billy5982 commented 17 hours ago

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