-
Notifications
You must be signed in to change notification settings - Fork 83
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
Styles should not rely on base font-size #380
Comments
I was able to make Primevue work with other Tailwind components which rely on a base font-size of 16px (or none - which is most browser's default). In order to make it work, we need to convert all rem values of the Primevue styles by a factor of 0.875 (14px/16px). This can be achieved with a custom postcss plugin and one additional css declaration. If you have defined a base font-size of 14px for Primevue, remove it. In the base.css (the file which contains the Primevue :root etc. styles add this at the bottom: .p-component {
font-size: 0.875rem;
} In your project folder, add a postcss-primevue.js (or whatever you want to name it) and insert this code: export default (options = {}) => {
const { scale = 0.875 } = options;
return {
postcssPlugin: 'postcss-primevue',
Once(root) {
const filePath = root.source?.input.file;
if (filePath && filePath.includes('primevue')) {
root.walkDecls(decl => {
if (decl.value.includes('rem')) {
decl.value = decl.value.replace(/(\d*\.?\d+)rem/, (_, num) => `${num * scale}rem`);
}
});
}
},
};
}; Finally, move your postcss.config.js to vite.config.js by adding this configuration: import postcssPrimevue from './postcss-primevue.js';
import postcssImport from 'postcss-import';
import tailwindcss from 'tailwindcss';
import autoprefixer from 'autoprefixer';
export default defineConfig({
css: {
postcss: {
plugins: [
postcssImport(),
tailwindcss(),
autoprefixer(),
postcssPrimevue({ scale: 0.875 }),
],
},
},
... You can then remove the postcss config in the postcss.config.js file by simply reverting it to: module.exports = {} since the postcss config is included in the vite config now. Restart vite and it should work now. Primevue styles should be scaled down by the factor of 0.875 which makes them visually compatible with other Tailwind libraries. |
I totally agree. This is very strange decision to "randomly" change base I understand that this is not a problem if you use PrimeVue from the beginning of your project and it is the only component library you use. But if you are trying to add PrimeVue to an existing project or you just trying to use some another component library alongside PrimeVue, then things break. You cannot just change base Actually, this doesn't work well as some values are hardcoded in the theme. For example I'm trying to understand the reason for this decision: change the default I understand that using all default themes with |
I found it much easier to keep 14px for base html size so that we won't have to make any PrimeNg changes. The list for Tailwind theme variables is pretty small and we can just update that to account for 14px base instead of 16px base. Since i updated base html font size from 16px to 14px i multiply all the rem values by 16/14. In Tailwind v4 we override the theme in styles.css file directly (there is no tailwind.config.cs) After this change both Tailwind version 4 and PrimeNg version 19 component appear to be ok in sizes. Try this and let me know if it works for you as well. I just tried this on a new test project. If someone thinks this can cause any other issue, let us know as well. Thanks ---in styles.css--- @theme { --spacing: calc(0.25rem * 16/14); --breakpoint-sm: calc(40rem * 16/14); --container-3xs: calc(16rem * 16/14); --text-xs: calc(0.75rem * 16/14); --radius-xs: calc(0.125rem * 16/14); html, body { |
First of all, great work on everything! The Tailwind preset looks great. However, there is one major issue with it. Since it requires a base font-size of 14px to be set on the html tag, it makes all other Tailwind-styled components incompatible which do not share this same base font-size.
Tailwind itself styles its components based on the default font-size of modern browsers, which is 16px. So no base font-size is set on the html tag.
Since not only font-sizes, but all kinds of size-based styles (width, height, spacing, etc.) are relative to the base font size (since Tailwind is using rem) it makes Primevue incompatible with any other Tailwind styled html component. It breaks app designs with existing Tailwind layouts. Or Primevue components are way bigger than displayed in the documentation (and bigger than they should be).
I think it is strongly recommended to remove the 14px restriction and restyle all components without the need of any base font-size. This way Primevue will be much more compatible with other frameworks, templates and snippets.
The text was updated successfully, but these errors were encountered: