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

airframe-rx-html: onMount may not be able to find the rendered DOM element #3453

Open
xerial opened this issue Mar 15, 2024 · 0 comments
Open
Labels

Comments

@xerial
Copy link
Member

xerial commented Mar 15, 2024

If an RxElement is rendered in a nested sequence, onMount can be called a bit earlier than rendered element actually appears in the browser.

An example:

class HoverableTextLabel(txt: RxElement, hoverMessage: String) extends RxElement:

  private val elementId = ULID.newULIDString

  override def onMount: Unit =
    RxDOM.getHTMLElementById(elementId).foreach { el =>
      try Dynamic.newInstance(Dynamic.global.bootstrap.Tooltip)(el)
      catch case e: Throwable => warn(e)
    }

  override def render: RxElement = span(
    id                   -> elementId,
    data("bs-toggle")    -> "tooltip",
    data("bs-placement") -> "top",
    data("bs-title")     -> hoverMessage,
    txt
  )

div(
  Seq[RxElement](
    HoverableTextLabel("hello", "mouseover message")
  )
)
@xerial xerial added the bug label Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant