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

Prefixes in components #132

Open
desprit opened this issue Apr 11, 2022 · 21 comments
Open

Prefixes in components #132

desprit opened this issue Apr 11, 2022 · 21 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@desprit
Copy link

desprit commented Apr 11, 2022

Describe the bug
Tooltip and Dropdown components don't work when tailwindcss prefix is set.

To Reproduce
Steps to reproduce the behavior:

  1. Setup prefix in the tailwind.config.js:
module.exports = {
  prefix: "tw-",
  ...
}
  1. Create a tooltip component https://flowbite.com/docs/components/tooltips/
  2. Add prefixes to default styles
  3. 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

@dan-valang
Copy link

I'm also having the same issue with the modal window

@zoltanszogyenyi
Copy link
Member

zoltanszogyenyi commented Jul 6, 2022

Will introduce prefixes for v1.5.

@zoltanszogyenyi zoltanszogyenyi self-assigned this Jul 6, 2022
@zoltanszogyenyi
Copy link
Member

@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.

@zoltanszogyenyi zoltanszogyenyi moved this from In Progress to Done in Flowbite Library Development Jul 8, 2022
@zoltanszogyenyi zoltanszogyenyi added the bug Something isn't working label Jul 8, 2022
@desprit
Copy link
Author

desprit commented Jul 9, 2022

This is great @zoltanszogyenyi , thank you very much!

@desprit desprit closed this as completed Jul 9, 2022
@BogdanCln
Copy link

BogdanCln commented Aug 21, 2022

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? 🤞

@adam-clio
Copy link

@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?

@AstrisDev
Copy link

Any chance to fix this issue in the next releases? v1.6.3 flowbite still not working properly with tailwind prefixes.

@bspyropoulos
Copy link

Any news on that?

@zoltanszogyenyi
Copy link
Member

zoltanszogyenyi commented Mar 8, 2023

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

@linpan
Copy link

linpan commented Jun 6, 2023

Tooltip and Dropdown components don't work when tailwindcss prefix is set. this bug waste me one day.

@fabarea
Copy link

fabarea commented Jun 12, 2023

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.

@1day2die
Copy link

damn this is still a bug? fuck me

@zoltanszogyenyi zoltanszogyenyi moved this from Done to In Progress in Flowbite Library Development Aug 31, 2023
@majermi4
Copy link

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!

@AmirJavaidSwe
Copy link

is this solved? i am also using prefix in tailwind tw- and seems due to that this isn't working for me

@fedegonzal
Copy link

fedegonzal commented Feb 28, 2024

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.

@0Chan-smc
Copy link

Why is this still not fixed? Even though the Flowbite version is 2.3!

@anejjar
Copy link

anejjar commented May 13, 2024

Any news about this please??

@victorwitei
Copy link

victorwitei commented May 27, 2024

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;
}

@Atydin
Copy link

Atydin commented Jul 8, 2024

Any news?

@Fejlip
Copy link

Fejlip commented Aug 30, 2024

Any updates on this? Would be greatly appreciated if this got added

@mbajur
Copy link

mbajur commented Jan 15, 2025

I can see that now all the components are using getPrefixedClassName function which adds the prefix from tailwind config. If there was any way to overwrite it's behaviour or be able to provide the prefix manually...

PS. Maybe there is, I'm just not JS fluent enough to tackle that by myself
PS2. @zoltanszogyenyi would that be acceptable to modify components code and proxy getPrefixedClassName via this.getPrefixedClassName method on each component so we can at least overwrite it's behaviour in a similar way @fedegonzal described? I'm talking about something like having a following code in the components:

class Drawer {
   ...

  _getPrefixedClassName(value) {
    return getPrefixedClassName(value)
  }
}

So at least we can do

drawerInstance._getPrefixedClassName = function(value) {
  return value.replaceAll('%p%', 'my-prefix-')
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
Status: In Progress
Development

No branches or pull requests