-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Problem using PrimeNG with TailwindCSS #14255
Comments
Looks like it's the same as #13757 |
Try this & make sure you update your tailwind config according to your tailwind version.
|
In angular 17 when using the new builder @layer tailwind-base, primeng, tailwind-utilities;
@import "tailwindcss/base" layer(tailwind-base);
@import "tailwindcss/components" layer(tailwind-utilities);
@import "tailwindcss/utilities" layer(tailwind-utilities);
@import "primeng/resources/themes/lara-light-blue/theme.css";
@import "primeng/resources/primeng.css"; It does not automatically add new tailwindcss classes to your build when using ng serve. Instead, if you ONLY put the preflight/reset in the layer then tailwindcss will add the classes. The following fix makes it so that you dont have to restart ng serve for every tailwindcss class change @layer tailwind-base, primeng;
@import "tailwindcss/base" layer(tailwind-base);
@tailwind components;
@tailwind utilities;
@import "primeng/resources/themes/lara-light-blue/theme.css";
@import "primeng/resources/primeng.css"; (not sure if this is a angular/angular-cli or a tailwindcss bug... but it's not a primeng bug) |
How I solved the problem for me.
// angular.json
"styles": [
"src/styles.scss",
"node_modules/primeng/resources/themes/lara-light-blue/theme.css",
"node_modules/primeng/resources/primeng.min.css"
],
// styles.scss
@layer tailwind-base, primeng, tailwind-utilities;
@layer tailwind-base {
@tailwind base;
}
@layer primeng; //not necessary I think
@layer tailwind-utilities {
@tailwind components;
@tailwind utilities;
}``` |
Same issue here
|
Responsive styles work for me after implement this solution, the only difference is that apart from all that, I added a prefix in tailwind.config.js file: |
I solved the problem by changing the order of the primeng imports /* Tailwind CSS */
@layer tailwind-base, primeng, tailwind-utilities;
/* Primeng Settings */
@import "primeng/resources/primeng.css";
@import "primeng/resources/themes/mira/theme.css";
@import "primeicons/primeicons.css";
@layer tailwind-base {
@tailwind base;
}
@layer tailwind-utilities {
@tailwind components;
@tailwind utilities;
} |
It is easy to use: @layer tailwind-base, primeng, tailwind-utilities;
@layer tailwind-base {
@tailwind base;
}
@layer tailwind-utilities {
@tailwind components;
@tailwind utilities;
} And, Add /** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,ts}"],
theme: {
extend: {},
},
plugins: [],
corePlugins: { preflight: false }
} |
@Stephan-MC 's solution worked for me too. Only thing I had to change was to put the |
why add the because just adding this to my css file is enough
|
I am on Angular 18.0.3 and I've tried everything I could find, yet nothing worked. The only thing that worked for me (after A LOT of trial and error) is this: @import 'tailwindcss/base.css' layer(tailwind);
@import 'tailwindcss/components.css' layer(tailwind);
@import 'tailwindcss/utilities.css' layer(tailwind);
@import 'primeflex/primeflex.css' layer(prime);
@import 'primeng/resources/themes/lara-light-blue/theme.css' layer(prime);
@import 'primeng/resources/primeng.css' layer(prime); You can put anything in EDIT: After some more testing, you can name the |
good luck |
Thanks @gitadam0 , your solution worked on my project as well (v17) but dynamic theming will be a pain in the butt. |
Hey again, so I solved most of my issues with 1 thing: |
Found another workaround since tailwind base was also clashing with primeng for us; ugly but does the job. I simply reverted the tailwind base layer that was overwriting primeng classes with @layer tailwind, prime;
@import 'tailwindcss/base.css' layer(tw-base);
@import 'assets/layout/styles/layout/layout.scss' layer(prime);
@import 'primeicons/primeicons.css' layer(prime);
@import 'assets/layout/styles/theme/tailwind/tailwind-light/theme.scss' layer(prime);
@import 'primeng/resources/primeng.css';
@import 'tailwindcss/components.css' layer(tw-components);
@import 'tailwindcss/utilities.css' layer(tw-utilities);
@import 'tailwindcss/variants.css' layer(tw-variants);
@layer tw-base {
[type='text'],
[type='email'],
[type='url'],
[type='password'],
[type='number'],
[type='date'],
[type='datetime-local'],
[type='month'],
[type='search'],
[type='tel'],
[type='time'],
[type='week'],
[multiple],
textarea,
select {
all: revert-layer !important;
}
} Works for the datatable for now, will probably run into more surprises when we get into the implementation of other primeng components... |
nice workaround and you can look in this page: |
no problem brother, what do you mean by dynamic theming |
Hello, If you've encountered issues with the order of CSS layers when using PrimeNG, avoid using both Make sure not to import files with the For example in your
I hope this helps ! :) |
How do you switch between themes (light/dark)? Because using "@import" is not dynamic. |
Tailwind preflight still overrides primeng classes in 19.0.2. My import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { appRoutes } from './app.routes';
import { provideClientHydration } from '@angular/platform-browser';
import { provideAnimations } from '@angular/platform-browser/animations';
import { provideHttpClient, withFetch } from '@angular/common/http';
import { providePrimeNG } from 'primeng/config';
import { LocalePl } from './primeng.pl.locale';
import Aura from '@primeng/themes/aura';
export const appConfig: ApplicationConfig = {
providers: [
provideClientHydration(),
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(appRoutes),
provideAnimations(),
provideHttpClient(withFetch()),
providePrimeNG({
ripple: true,
translation: LocalePl,
theme: {
preset: Aura,
options: {
cssLayer: {
name: 'primeng',
order: 'tailwind-base, primeng, tailwind-utilities'
},
}
}
})
],
};
@import 'primeicons/primeicons.css';
@layer tailwind-base, primeng, tailwind-utilities;
@layer tailwind-base {
@tailwind base;
}
@layer tailwind-utilities {
@tailwind components;
@tailwind utilities;
}
// import Quill styles in styles.scss
@import 'quill/dist/quill.core.css';
@import 'quill/dist/quill.snow.css'; |
Describe the bug
When using primeng and tailwindcss together the preflight styles from tailwind overwrite the some styles from primeng.
Buttons and borders are primarily affected by this. All borders are missing. The Table is not striped with p-datatable-striped set in styleClass
Environment
I am using node 20 with angulat 17. The problem also occurs with version 16
Reproducer
No response
Angular version
17
PrimeNG version
17
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
20
Browser(s)
Every Browser
Steps to reproduce the behavior
Expected behavior
The PrimeNG Styles should be more important than the tailwind preflight styles.
The Button should render its background colors and all borders should be displayed correct.
The text was updated successfully, but these errors were encountered: