Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: initializing rendered HTML nodes via javascript #293

Closed
soypat opened this issue Jan 15, 2022 · 4 comments
Closed

question: initializing rendered HTML nodes via javascript #293

soypat opened this issue Jan 15, 2022 · 4 comments

Comments

@soypat
Copy link
Collaborator

soypat commented Jan 15, 2022

Hey there! I need to initialize some Material Design components I rendered with vecty with a little bit of javascript, see here.

The initialization is simple enough, just call the constructor on the html node using getElementByID or similar. How would I go about this? I've been appending javascript unsafely to the end of my document but it is not exactly stable. See https://github.com/soypat/mdc/blob/main/examples/datatable/datatable_example.go#L68.

I think my unsafe approach would work better if I could somehow register a callback that is triggered once my component is rendered in the DOM. What would be the vecty way of doing this? Should we be looking for added API to see this work?

@soypat
Copy link
Collaborator Author

soypat commented Jan 15, 2022

I think Material Design expects the user to also hold onto the javascript handle to the component so as to have feedback to user inputs i.e. Current level of the slider.

@emidoots
Copy link
Member

I don't know anything about Material Design, but there are some others who have used it with Vecty in the past:

You should make certain that any DOM elements the material design library will attempt to modify on its own are isolated, i.e. using a vecty.Div with vecty.UnsafeHTML so that it is treated as an opaque element not owned by Vecty. See code example and further discussion around this in #236 (comment)

The other things you may wish to look at are the Mounter, Unmounter, and RenderSkipper interfaces:

Hope that helps!

@soypat
Copy link
Collaborator Author

soypat commented Jan 15, 2022

@slimsag Thank you so much! I'll look into it!

@soypat
Copy link
Collaborator Author

soypat commented Jan 16, 2022

@slimsag sure enough Mount and RenderSkip worked like a charm. HAve not gotten around to using Unmount() yet, but if it works like I think it does and given Material.js has destroyer methods, should work just fine. Thank you again for your amazing explanations and for maintaining this great package 👍

For posterity, here's the fix I applied: soypat/mdc@ea67825. Look for the Mount() and RenderSkip() implementations on Slider and Tooltip types.

@soypat soypat closed this as completed Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants