ui
ui copied to clipboard
fontFamily is not applied in tailwind.config.js file
When I comment out the code below from tailwindcss.config.cjs
file, I get sans-fonts displayed. Otherwise I get serif-fonts with the sans
key somehow. How to get proper fonts?
fontFamily: {
sans: ['var(--font-sans)', ...fontFamily.sans],
},
@lightbluepoppy Are you using a src
directory? I had this issue but I realized I didn't update the tailwind.config content
to find files within my src
directory. Now I'm having an issue with it not applying to dropdown menu.
@bluengreen This looks correct.
content: ['./src/**/*.{js,ts,jsx,tsx}'],
@lightbluepoppy I'm not using the app
router so I had to do some other things that solved my dropdown menu typography issue. I needed to update the _app.tsx
and the _document.tsx
.
In the _document.tsx
I had to add this
<body className={`min-h-screen bg-background ${fontSans.variable} font-sans antialiased`}>
and in the _app.tsx
I added a html wrapper and added the font-sans there as well
<main className={`${fontSans.variable} font-sans`}>
I thought it was weird it needed to be added in both places. Not sure how relevant that is for your use case but maybe that will trigger some ideas. Good luck!
So if you are following the manual install guide @lightbluepoppy you'll find this issue as the css variable is not defined anywhere when doing a manual install 'var(--font-sans)' so resolving that fails and it falls back to a serif font. You can either define that css variable in the same css file you've defined the rest of the variables or you can just remove the variable usage and just use ...fontFamily.sans
Docs should be updated, this got me too - https://ui.shadcn.com/docs/installation/manual
Guys. have you been able to resolve the issue? I am getting same issue on my side.
Guys. have you been able to resolve the issue? I am getting same issue on my side.
See my proposed fix above!
Guys. have you been able to resolve the issue? I am getting same issue on my side.
See my proposed fix above!
Thanks @pmabres I have resolved the issue :). The issue was in tailwind.config.js
file. There were two extend properties I was writing one for colors, borderRadius, animation (shadcn already written this) and one for fontFamliy (I was writing).
for me issue was that in root layout i was passing font.className but need to be font.variable
Just for anyone who does not like to read @pmabres solution (a) looks like this:
from
fontFamily: {
sans: ["var(--font-sans)", ...fontFamily.sans],
},
to
fontFamily: {
sans: [...fontFamily.sans],
},
Worked for me thanks!
the following worked for me after adding the import statement in tailwind.config.js
import { fontFamily } from "tailwindcss/defaultTheme"
module.exports = {
..
theme:{
...
extend: {
fontFamily: {
sans: ["var(--font-sans)", ...fontFamily.sans],
},
}
}
..
}
This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.