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

Does initFlowbite perform asynchronous work on attributes? #813

Open
reubenfirmin opened this issue Feb 23, 2024 · 0 comments
Open

Does initFlowbite perform asynchronous work on attributes? #813

reubenfirmin opened this issue Feb 23, 2024 · 0 comments

Comments

@reubenfirmin
Copy link

reubenfirmin commented Feb 23, 2024

Is your feature request related to a problem? Please describe.
The issue I'm trying to solve: when I click on a popper menu to load the settings page, the popper menu stays open. The settings page is loaded with htmx, which of course is regenerating the content of part of the page (but not the navbar containing the popper menu).

To address this, I added on a function in HTMX.onLoad (this is kotlinjs, but it maps pretty cleanly to js):

        window.asDynamic().htmx.onLoad {
            initFlowbite()
            initCharts()
            FlowbiteHelpers.clearOpenElements() // this one
        }

clearOpenElements attempts to do this:

        val elements = document.querySelectorAll("[data-popper-placement]")
        for (i in 0 until elements.length) {
            val el = elements.item(i)!! 
            (el as HTMLElement).style.display = "none"
        }

This didn't work. Adding introspection of the dom via console logging in this function, I can see that the "data-popper-placement" attribute is in fact missing from the div when the function runs. However, I can run console logging from the console and see the attribute. This makes me think that there might be something asynchronous happening after initFlowbite() runs - is that the case?

And - general request - I think initFlowbite should clear any open elements like this. Maybe there's a reason not to, but in that case please make a stable way for us to find elements by attribute.

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