Javascript inject in Perspective... have fun

Yup, you're exactly right, runJavaScriptAsync won't work for this :confused:

I do have one other option: use the events.target.lifecycle.onMount callback of the Portal component.

The Portal component doesn't have any documentation written yet... but, basically, it allows you to interact with a DOM element and directly insert children.

A side-feature is the events.target.lifecycle functions. Here, you can add functions that will run when the target element loads, unloads, or updates. For example:

# element (DOM ID or arrow function that returns a reference to a node).
TextField
# events.target.lifecycle.onMount
(element) => element.focus()

This is pretty much the same thing as the Markdown component injection version though, just with a little more hand-holding.

Edit:
There is an issue with the Portal component that hasn't been fixed yet; it doesn't listen for DOM changes after the first render. This means the Portal component must load after the target.
Until this issue is fixed, the Portal component doesn't have an advantage over the Markdown injection technique. Once it's fixed, it won't be load order sensitive.

2 Likes