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

CSS @layer primereact is not working with Bootstrap/MUI #5124

Closed
kabalan-datapostie opened this issue Oct 20, 2023 · 10 comments
Closed

CSS @layer primereact is not working with Bootstrap/MUI #5124

kabalan-datapostie opened this issue Oct 20, 2023 · 10 comments
Assignees
Labels
Resolution: Wontfix Issue will not be fixed due to technical limitations

Comments

@kabalan-datapostie
Copy link

Describe the bug

Use case: PrimeReact is a fantastic theme and component library. Other CSS toolkits (e.g. Bootstrap, Tailwind, Materialize, etc.) provide useful utilities on top of it like grid, spacing, and much more. So, it's a common use case to use themed PrimeReact with these other "utility" CSS libraries, and want PrimeReact to take precedence over these utility libraries.

The problem: this use to work well. However, PrimeReact 10.x removed the "core" PrimeReact library in favour of only needing to import the style library, and added layers to the themed libraries. These layers mean that the other utility libraries (Bootstrap etc.) now take precedence over core PrimeReact classes.

Potential solutions:

  • Provide an elegant way (in CRA and Next.js) to add a layer to the utility library (e.g. Bootstrap) and make the PrimeReact layer take precedence. This would be great, but it seems a lot easier to make a change to PrimeReact than maintain fixes for all other commonly used utility libraries.
  • Only add @layer primereact when working with the unstyled version of PrimeReact.
  • Add an option to import themed PrimeReact with or without the @layer
  • Other?

Note: this issue is related to issue #4987, but the conversation veered more towards unstyled PrimeReact and specific to Tailwind, whereas this is a more ubiquitous issue caused by layers in 10.x that other commenters in that issue have mentioned.

Reproducer

https://codesandbox.io/s/primereact-test-forked-hc22hc?file=/src/index.js

PrimeReact version

10.0.5

React version

18.x

Language

ES6

Build / Runtime

Next.js

Browser(s)

Chrome 118

Steps to reproduce the behavior

See reproducer

Expected behavior

See reproducer and use case in bug description

@kabalan-datapostie kabalan-datapostie added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Oct 20, 2023
@melloware melloware added Component: Theme Issue or pull request is related to Theme Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Oct 20, 2023
@melloware
Copy link
Member

Assigned to PrimeTek.

@yrios-cdd
Copy link

I use primereact in an app that also uses Bootstrap, when upgrading to version 10.0.2 the styles are breaking because Bootstrap styles are taking precedence over the PrimeReact theme.

@melloware melloware added Component: Tailwind Tailwind specific issue and removed Component: Theme Issue or pull request is related to Theme labels Oct 27, 2023
@melloware
Copy link
Member

Bootstrap instructions: https://primereact.org/bootstrap/

@melloware melloware removed Type: Bug Issue contains a defect related to a specific component. Component: Tailwind Tailwind specific issue labels Nov 13, 2023
@yrios-cdd
Copy link

Bootstrap instructions: https://primereact.org/bootstrap/

@melloware @kabalan-datapostie

This solution does not solve my problem.
My case is different, I use Primereact components inserted in a legacy multipage application where the layout is built using Bootstrap, so the Bootstrap CSS files are loaded independently of React. My goal is to continue using the primereact/resources/themes/bootstrap4-light-blue/theme.css theme in the Primereact components and have the theme styles take precedence over the bootstrap styles loaded in the layout of the app. That way we have been using Primereact until version 10.0.2.
How can we continue using Primereact in this way in the new versions after 10.0.2, without having to opt for the "Unstyled mode" and "Pass Through"?

@melloware
Copy link
Member

can you put together a Stackblitz showing your issue @yrios-cdd ?

@kabalan-datapostie
Copy link
Author

kabalan-datapostie commented Nov 14, 2023

I agree with @yrios-cdd - the use case here is that we want to use PrimeReact themes (in my case for instance mdc-indigo), but want to also use the "utility" (e.g. flex, spacing, etc.) classes of other libraries, say bootstrap. So, we want themed PrimeReact to take precedence over external libraries.

If I understand correctly, https://primereact.org/bootstrap/ fulfills the opposite case: where we want to use the theming of the external libraries, and have them take precedence over PrimeReact unstyled.

So the reproducer above stays valid: https://codesandbox.io/s/primereact-test-forked-hc22hc?file=/src/index.js

@yrios-cdd
Copy link

can you put together a Stackblitz showing your issue @yrios-cdd ?

@melloware The one shown by @kabalan-datapostie is valid, only this one installs and imports Bootstrap and in my case Bootstrap is loaded separately in the app layout template using <!-- Bootstrap --> <link rel="stylesheet" type="text/css" media="screen" href="{% static 'bootstrap/5.0.1/css/bootstrap.min.css' %}"/>, but it's the same case.

@melloware
Copy link
Member

Yep I see it I think I will rename this ticket to Bootstrap specifically as Bootstrap does not appear to support @layer like Tailwind does.

@melloware melloware reopened this Nov 14, 2023
@melloware melloware added the Type: Bug Issue contains a defect related to a specific component. label Nov 14, 2023
@github-actions github-actions bot added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 14, 2023
@melloware melloware changed the title PrimeReact 10.x layers make themed PrimeReact not work well with other CSS libraries CSS @layer primereact is not working with Boostrap Nov 14, 2023
@melloware melloware changed the title CSS @layer primereact is not working with Boostrap CSS @layer primereact is not working with Bootstrap Nov 14, 2023
@melloware melloware removed the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 14, 2023
@melloware melloware changed the title CSS @layer primereact is not working with Bootstrap CSS @layer primereact is not working with Bootstrap/MUI Dec 23, 2023
@yrios-cdd
Copy link

Any estimate of when a solution to this problem might be released?
I am still unable to migrate to version 10.

@melloware
Copy link
Member

From Optimus on Discord: https://discord.com/channels/787967399105134612/787968635414118421/1205480133855678524

Bootstrap is not super suitable to unstyled mode, it has css based components that accept a certain DOM. Tailwind is the best fit for the styled mode. I don't think you can do a full bootstrap theme, it is not powerful enough to style all the components of Prime. But Tailwind is so we created the Tailwind Presets projects based on this idea. Bulma, Bootstrap have an opinionated approach which is not compatible.

@melloware melloware added Resolution: Wontfix Issue will not be fixed due to technical limitations and removed Type: Bug Issue contains a defect related to a specific component. labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Wontfix Issue will not be fixed due to technical limitations
Projects
None yet
Development

No branches or pull requests

5 participants