You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically I have an action which adds a CSS class to an element when it is reached. The problem is that the selector is removed by the compiler because the class is not referenced anywhere. In most cases, I would just use :global() in my SCSS to work around this. However in this case, I have to do this from a mixin which adds the class with an ampersand rule and it does not let me use :global() in this case. For example:
/* Does not work */
@mixin my-mixin() {
&.reached {
/* my style here */
}
}
/* Does not want to compile */
@mixin my-mixin() {
:global(&.reached) {
/* my style here */
}
}
I also have tried a version using :is(.reached) instead which I believe used to work, but not with Svelte 5.
I guess it could be tweaked by adding the class in another way with a state, but this is used quite lot in many components and multiple times by components, so it's cleaner to just be able to use:action and neatly hide all this.
Am I missing something ? Or is my case just too convoluted and I need to do it in a different way ? I'd like to keep this in a mixin because it does quite a lot of complicated things that are used in a lot of places on my website.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Basically I have an action which adds a CSS class to an element when it is reached. The problem is that the selector is removed by the compiler because the class is not referenced anywhere. In most cases, I would just use
:global()
in my SCSS to work around this. However in this case, I have to do this from a mixin which adds the class with an ampersand rule and it does not let me use:global()
in this case. For example:I also have tried a version using
:is(.reached)
instead which I believe used to work, but not with Svelte 5.I guess it could be tweaked by adding the class in another way with a state, but this is used quite lot in many components and multiple times by components, so it's cleaner to just be able to
use:action
and neatly hide all this.Am I missing something ? Or is my case just too convoluted and I need to do it in a different way ? I'd like to keep this in a mixin because it does quite a lot of complicated things that are used in a lot of places on my website.
Beta Was this translation helpful? Give feedback.
All reactions