flowbite
flowbite copied to clipboard
Prefixes in components
Describe the bug Tooltip and Dropdown components don't work when tailwindcss prefix is set.
To Reproduce Steps to reproduce the behavior:
- Setup prefix in the tailwind.config.js:
module.exports = {
prefix: "tw-",
...
}
- Create a tooltip component https://flowbite.com/docs/components/tooltips/
- Add prefixes to default styles
- Launch your app and see tooltip not working
Expected behavior Components support custom prefixes
Desktop (please complete the following information):
- OS: MacOS
- Browser: Chrome
- Version: 100.0.4896.75
Additional context Components have default tailwindcss classes hardcoded: https://github.com/themesberg/flowbite/blob/main/src/components/tooltip.js#L70 and there is no prefix injection there
I'm also having the same issue with the modal window
Will introduce prefixes for v1.5.
@desprit @dan-valang
This is now fixed on the develop branch by using a special function that introduces the prefix to all injected classes.
It will directly look into the tailwind.config.js file and using the getPrefixedClassName and getPrefixedClassName functions it will introduce the prefix, if it's being set.
Source: https://github.com/themesberg/flowbite/blob/develop/src/components/modal.js
Another feature is that you will be able to set the prefix for the data attributes too, such as data-fb-dropdown-toggle by adding it in the flowbite.config.js file like this:
module.exports = {
prefix: 'fb-'
}
This will be pushed to NPM for the v1.5.
This is great @zoltanszogyenyi , thank you very much!
This will be pushed to NPM for the v1.5.
Hello @zoltanszogyenyi,
Thank you for this great module.
Will the getPrefixedClassName changes be pushed to NPM eventually? 🤞
@zoltanszogyenyi we're on 1.6 now and these changes are still in develop. Any chance they're going to make it into the next release?
Any chance to fix this issue in the next releases? v1.6.3 flowbite still not working properly with tailwind prefixes.
Any news on that?
Hello everyone,
I'm trying my best to get this out in the next release, unfortunately I'm the only one maintaining the repository right now and it's a bit difficult to keep up with other issues as well. A branch has already been started and theoretically there's not too much left to do - the way it will work is that it will automatically take the prefix settings from the tailwind.config.js file.
Can't give an ETA but it should be live in the next couple of months.
Thanks <3
Zoltan
PS: PR's are more than welcome for help, it's an open-source project
Tooltip and Dropdown components don't work when tailwindcss prefix is set. this bug waste me one day.
Same. I can confirm that the prefixing will cause an issue with the toggle component. When prefixing is applied, the toggle component fails to display the larger "dot" element.
damn this is still a bug? fuck me
Hi, we love Flowbite and we would like to use it as a base for our project. However, we're in the process of migration between 2 tailwind and bootstrap and custom theme with similar utility classes like bootstrap. That's why we need to add prefixes to all tailwind classes which is why I got here. I realised that we cannot use the provided JS because it doesn't add prefixes to classes.
Is there any chance this is going to be fix/released soon or some workaround for time being?
Thank you!
is this solved? i am also using prefix in tailwind tw- and seems due to that this isn't working for me
Hi, I had the same problem. I'm using "tw-" as a prefix (take a look at my example below). Based on the dropdown code, https://github.com/themesberg/flowbite/blob/main/src/components/dropdown/index.ts I made a workaround while the official fix is ready:
// be sure this script is loaded after flowbite
window.onload = function() {
// loops through all dropdowns and initializes them
document.querySelectorAll('[data-dropdown-toggle]').forEach(($triggerEl) => {
const dropdownId = $triggerEl.getAttribute('data-dropdown-toggle');
const $dropdownEl = document.getElementById(dropdownId);
// creates a new instance of the dropdown
let dropdownInstance = new Dropdown($dropdownEl, $triggerEl);
// overrides the show and hide methods with your desired prefix
// I'm using tw- as an example, but you can use any prefix you want
dropdownInstance.show = function() {
this._targetEl.classList.add('tw-block');
this._targetEl.classList.remove('tw-hidden');
this._setupClickOutsideListener();
// update its position
this._popperInstance.update();
this._visible = true;
};
dropdownInstance.hide = function() {
this._targetEl.classList.add('tw-hidden');
this._targetEl.classList.remove('tw-block');
this._visible = false;
this._removeClickOutsideListener();
};
});
};
I'm sure it could be better, but works.
Why is this still not fixed? Even though the Flowbite version is 2.3!
Any news about this please??
I have found a fix for the dropdown's based on CSS, at least with this fix I can avoid add more JS to my file:
[data-dropdown-toggle] + .block {
display: block;
}
[data-dropdown-toggle] + .hidden {
display: none;
}
Any news?