tamagui: Default font family not being passed down to Text component on Web
Hey, tried to necro an old issue about this but since its closed i believe it never notified anyone.
I have this issue on release 1.76.0.
Environment:
- Web: Vite@4.3.0
Reproduction:
- Simply install the sample project with npm create tamagui@latest
- Edit src/Root.tsx to include two Text components as follows:
<TamaguiProvider config={config} defaultTheme="light">
<YStack f={1} ai="center" jc="center">
<Text fontFamily='$body' fontSize={50}>Hello world</Text>
<Text fontSize={50}>Hello world</Text>
</YStack>
</TamaguiProvider>
- Run yarn dev:vite
- Notice how both text components render differently, one with a font family and one with default browser’s font.
I believe this is the best way to explain this issue since it uses the sample project as reproduction repo.
In native, this works correctly and you may skip the fontFamily prop for all Text components, hence why i believe this is a bug on web, if it something i missed and this is on purpose please let me know.
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Reactions: 1
- Comments: 16 (6 by maintainers)
For info, not initializing an
unsetprop inuseFontbut addingdefaultFont: 'body'in tamagui.config.js is working as natew answered.It works for me in the simple starter but you need to set
defaultFont. Once I set it, it looks good:@junioroga I managed to solve this. You need to have a global.css file for web at the root of your repo
for example
Then in the root _layout.js >
import ‘…/global.css’;
and of course >
Hope that helps
@anthonyn60 @jordam1407 In initializing your fonts, just add “unset” key and add your default font as value
Not sure if it’s related to the latest changes as well, but I’m getting the following error related to the “unset” keyword additions in the latest versions (according to the release notes):
This happens when I use Expo Go on iOS 17. I’m on the latest version of Tamagui (
1.79.1)There could be something odd happening with defaults and this keyword?
It seems that font explicitly does not inherit color and font properties. My team uses SizableText as the default text https://tamagui.dev/docs/components/text/1.0.0