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

react compatibility react.createElement and eventEmitter based HTMLElement #526

Open
wibed opened this issue Feb 21, 2024 · 1 comment
Open

Comments

@wibed
Copy link

wibed commented Feb 21, 2024

afaik geocoder produces an wrapped input htmlelement which i am unable to convert into a viable react.element.

i tried something along those lines:

        const geocoderNode: HTMLElement = ctrl.onAdd(mapboxMap)

        const geocoderInputChildren = Array.from(geocoderNode.children).filter(el => el.tagName.toLowerCase() === "input")
        if (geocoderInputChildren.length === 0) { throw new Error("missing input element") }
        const geocoderInput: HTMLInputElement = geocoderInputChildren[0] as HTMLInputElement

        const geocoderInputNode = React.createElement(
          geocoderInput.tagName.toLowerCase(),
          { class: geocoderInput.className, type: "text", placeholder: "Search", ariaLabel: "Search" }
        )

        const GeocoderNode: JSX.Element = React.createElement(
          geocoderNode.tagName.toLowerCase(), 
          { className: geocoderNode.classList },
          geocoderInputNode
        )

but done this way any connection to the events are lost.

only when i use above example like this i am able to keep the events

        ...
        const geocoderNode: HTMLElement = ctrl.onAdd(mapboxMap)
        containerNode.appendChild(geocoderNode)
        ...

which breaks compatibility with react and its virtual dom.

how can i work around this to keep functionality and react compatibility?

why bother? you might ask.
id like to control the results from the input element via react-hook-form but unable to do so due to lack of compatibility.

@wibed
Copy link
Author

wibed commented Feb 22, 2024

i have all these events within the browser:
image

yet cant make out a single one within programatically
id access them like this

        const geocoderNode = ctrl.onAdd(mapboxMap)
        // START INSPECTION HERE BUT...
        const geocoderInputChildren = Array.from(geocoderNode.children).filter(el => el.tagName.toLowerCase() === "input")
        if (geocoderInputChildren.length === 0) { throw new Error("missing input") }
        const geocoderInput= geocoderInputChildren[0]
        // ...CANT FIND ANY EVENTS PROGRAMMATICALLY
        containerNode.appendChild(geocoderNode)

what could be the reason
i am trying to copy the events over from a htmlelement into a compatible react element
i tried using the following

        const geocoderInputNode = React.createElement(
          geocoderInput.tagName.toLowerCase(),
          { className: geocoderInput.className, type: "text", placeholder: "Search", "aria-label": "Search" }
        )

        const GeocoderNode: JSX.Element = React.createElement(
          geocoderNode.tagName.toLowerCase(), 
          { className: geocoderNode.classList },
          geocoderInputNode
        )

expected to be successfull but ended up with these events instead
image

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

1 participant