ui: [bug]: The style overrides by shadcn for sonner are not working.
Describe the bug
From the screenshot, it is evident that the styles added by shadcn have a lower priority than the inherent styles of sonner , and therefore cannot override them correctly.
Affected component/components
Sonner
How to reproduce
- install shadcn/ui
style: default
baseColor: gray
cssVariable: false
- install sonner by
npx shadcn-ui@latest add sonner - use sonner in my project
Codesandbox/StackBlitz link
No response
Logs
No response
System Info
System: macOS 14.2.1
Browser: Arc Version 1.39.0 (48951) / Chromium Engine Version 124.0.6367.61
Before submitting
- I’ve made research efforts and searched the documentation
- I’ve searched for existing issues
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 4
- Comments: 33 (1 by maintainers)
Commits related to this issue
- Rollback sonner to correct styling bug Check up on here https://github.com/shadcn-ui/ui/issues/3579 — committed to skyfenton/waller by skyfenton 2 years ago
Make sure when you import Toaster in your project you import it from your shadcn components and NOT the sonner lib, I acidently did it from the sonner lib and was wondering why it was not working.
Hey everyone,
Regarding needing to specify
!important, the creator of sonner has confirmed that this is the expected behaviour.Source:
As a workaround, you can use the “!” character before a tailwind class. Since the problem only affects the buttons (as far as I can see) you can use the following styles:
Works in 1.5.0.
@anson0370 | cc: @skyfenton @sitenativedev @christian1koch @Phygon @code-xhyun
Might be some help here: I actually ended up modifying my sonner ui component file. Simply by adding a few lines to the toast Classname I was able to get some of the old feel back:
What changed:
h-auto w-full p-4 rounded-md borderIts not perfect but it will get you some of the way there.
After hundreds of tinkering with my config, this is basically the problem. For some reason, the sonner styles are not added by default. I tried importing it as you said, but its the “same”. My issue was a bit odd. I am in v2. The height was super collapsed, css was nowhere. What I did, is to import sonners css in my css file (copy and paste from repo, nothing worked for some reason).
import “sonner/dist/styles.css”;
apply this on root file
Sonner in version 1.7.0 provides a dist/styles.css.
When I include that in my app like this in one of JS files, the styling is correct:
import '../node_modules/sonner/dist/styles.css';<Toaster richColors />Need to add prop richColors
Modifying this component at all is such a fucking mess it goes against the original idea of shadcn. I have no idea who on their end thought this was alright.