Skip to content

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

@xerial

Description

@xerial

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")
  )
)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions