Shmew / Feliz.MaterialUI

Feliz-style Fable bindings for Material-UI
https://shmew.github.io/Feliz.MaterialUI/
MIT License
70 stars 19 forks source link

dialog.transitionComponent prop #47

Open ghost opened 4 years ago

ghost commented 4 years ago

What is the proper way to use the transitionComponent prop for dialogs? The Material UI documentation uses the forwardRef function as

const Transition = React.forwardRef(function Transition(props, ref) { return <Slide direction="up" ref={ref} {...props} />; });

but the Feliz.React.forwardRef function returns a ReactElement rather than a ReactElementType. Is there an additional function call required to convert from ReactElement to ReactElementType, or is there a simpler way to go about this?

Shmew commented 4 years ago

Hi @ShaneMasuda, try unboxing and see if it works.

ghost commented 4 years ago

@Shmew unboxing the return value of the forwardRef function into a ReactElementType? That doesn't seem to work for me, and neither does the following

Capture

as I get a console error saying the slide component can't read the property 'ref' of undefined.

Shmew commented 4 years ago

I think this will work unbox<ReactElementType>(System.Func<_,_,_> transition)

@cmeeren, @zaid-ajaj thoughts on how APIs that need ReactElementType can be better handled?

ghost commented 4 years ago

@Shmew so I tried that as

Capture2

but it seems the slide component still doesn't know about the ref. Namely, I'm getting the following error:

Capture3

Am I perhaps not using the forwardRef function correctly? Thank you for responding so quickly btw!

Shmew commented 4 years ago

Yeah, you're using it correctly. I'm not really sure you even need it here, you could just try making the element itself and unboxing that, or unbox<ReactElementType>(System.Func<_,_,_>(fun props ref -> transition(props,ref))

Thank you for responding so quickly btw!

You're welcome!

ghost commented 4 years ago

Unboxing the element itself yielded this:

Capture5

and using the last line yielded this:

Capture4

Is there any way you could try to get a simple example dialog with a transitionComponent up and running on your end? It would be greatly appreciated!

Shmew commented 4 years ago

I just spent some time trying to figure this out, I'm not sure how to fix it right now :(. I could have sworn I already battled this issue before.

ghost commented 4 years ago

No worries! If any updates happen I'll be here. In the meantime I can work around it by making my own backdrop and making the dialog a child of the slide component.

cmeeren commented 4 years ago

@Zaid-Ajaj do you have any input here (see OP)? React.forwardRef is from Feliz, I suppose?

Zaid-Ajaj commented 4 years ago

@cmeeren I have no idea, a reproducible example would be nice to see so that we can test what the problem is and compare with how the code looks like in native Mui

marcpiechura commented 3 years ago

Hey,

I run into the same issue. @ShaneMasuda have you been able to resolve this one or are you still using your workaround?

thanks.

ghost commented 3 years ago

@marcpiechura @Shmew @Zaid-Ajaj coming back to this issue because I found a fix, I created a ReactElementType from scratch and combined the keys and values manually as custom props, which seems to do the trick:

image

The main issue here is that React.forwardRef always seems to yield null for the ref. Please let me know if anything changes!