alexkatz / react-tiny-popover

A simple and highly customizable popover react higher order component with no other dependencies! Typescript friendly.
MIT License
454 stars 121 forks source link

Pass `position` to children #70

Closed stefanzmf closed 3 years ago

stefanzmf commented 4 years ago

Hello,

I was wondering if you have taken this into consideration. Basically I want to use this for a dropdown menu (the options are going to be rendered in a popover) and would be very useful to know inside children where the popover is placed (to apply custom style on 'trigger').

I have tried using some ref (since state is not allowed), but still is not fine since on the 1st render the position is not available. I guess an onReposition callback or maybe a functional child component...?

Not really sure the impact of this feature, because I expect a lot of renders will happen, but I ll fork the project and give it a try.

Does anybody have an idea if there is a way of achieving this using the extension as it is?

alexkatz commented 3 years ago

Hi @stefanzmf, what you're asking should be possible with the current api.

If you supply a ContentRenderer function to Popover's content property, popoverRect, as well as childRect and parentRect are injected to the function as part of PopoverState.

I'll close this for now, but do let me know if I actually misunderstood your question. Thanks!