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

InitTE method doesn't reinitialize components in frameworks with routing (for example vue + vue-router) #1893

Closed
juujisai opened this issue Aug 25, 2023 · 7 comments · Fixed by #1919
Assignees
Milestone

Comments

@juujisai
Copy link
Contributor

juujisai commented Aug 25, 2023

#1891

@juujisai juujisai converted this from a draft issue Aug 25, 2023
@juujisai juujisai added this to the v1.0.0-rc.2 milestone Aug 25, 2023
@smessmer
Copy link

smessmer commented Sep 7, 2023

Running into the same issue with the leptos framework when navigation between pages causes HTML elements to be deleted/created.

@juujisai juujisai self-assigned this Sep 7, 2023
@juujisai juujisai modified the milestones: v1.1.0, v1.0.0 Sep 7, 2023
@juujisai juujisai linked a pull request Sep 7, 2023 that will close this issue
@juujisai
Copy link
Contributor Author

juujisai commented Sep 7, 2023

@smessmer We are going to change the initTE method a little bit. Inside the second parameter we will be able to provide options, for example allowReinits. That should help with routing issues.

Example of usage:

    import { Datepicker, Input, initTE } from "tw-elements";
    initTE({ Datepicker, Input }, { allowReinits: true });

@smessmer
Copy link

smessmer commented Sep 7, 2023

I'm using the UMD setup, i.e. I don't call initTE explicitly. Will your changes still fix this?

@juujisai
Copy link
Contributor Author

juujisai commented Sep 8, 2023

@smessmer UMD format also uses initTE method, but it's beeing called by default. If the method runs when your html is ready then it should work fine. Otherwise you would be able to call it again. For example:

import * as te from "tw-elements"       --- if needed

const componentList = {
  Input: te.Input,
  Timepicker: te.Timepicker,
};

te.initTE(componentList, { allowReinits: true });)

@smessmer
Copy link

oh so allowReinits would still require it to be called, I had thought it would automatically re-init whatever gets added to the DOM. Hm. Calling initTE on every DOM change is not easy to do in leptos. The route I described in the other issue of adding <script>new te.Input(document.getElementById("..."))</script> to every <input> element is more feasible but doesn't seem ideal either. Isn't there some way to automate this inside of Tailwind Elements?

@juujisai
Copy link
Contributor Author

@smessmer In your case, initializing via JS seems to be the best option.

@hellyanggara
Copy link

hellyanggara commented Sep 14, 2023

initTE({ Datepicker, Input }, { allowReinits: true });

I was looking for this answer all over the place, thx a lot

they should put this in vue integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants