themesberg / flowbite

Open-source UI component library and front-end development framework based on Tailwind CSS
https://flowbite.com
MIT License
7.61k stars 715 forks source link

Reference objects initialized via CDN #624

Closed alexsotir closed 10 months ago

alexsotir commented 1 year ago

When using the CDN version, it automatically initializes all your components (Dropdowns, Modals, etc.). The problem with that is that if you want to reference a specific component in order to control it programmatically, you will have to re-initialize it.

For example to close a Dropdown using code, you will need to do this: new Dropdown($dropdownEl, $triggerEl).hide();

Not only the above method is not best practice for many reasons, but for Modal it doesn't even work properly because creating a new Modal() object will also duplicate the backdrop / overlay (see #454 )

We need a way to either reference the objects that were already created by the CDN version or ideally stop initializing it automatically and let us do it manually using JS so we can reference it later.

I know it sounds great to just include the CDN and some HTML and have it work without any JS, but the amount of issues this creates is overwhelming.

zoltanszogyenyi commented 11 months ago

Hey @alexsotir,

Sorry for the late reply - started working on a PR for this.

https://github.com/themesberg/flowbite/pull/680

Cheers, Zoltan

zoltanszogyenyi commented 10 months ago

Hey @alexsotir,

Finished a new Instance Manager with the new Flowbite v2.0 update.

Please read more about it here:

https://flowbite.com/docs/getting-started/javascript/ https://github.com/themesberg/flowbite/releases/tag/v2.0.0

Cheers, Zoltan