-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Provide an option to disable CSS scoping or auto-generated class names in components #15613
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
Comments
Although I disagree with using a global CSS file to style all components of an application, I strongly believe that a rework on how scoped classes are being applied should happen as it is practically impossible to style an imported component unless it's used as a child of another element. The ProblemLet's suppose we have a general <script>
let { tag = "div", class: className, children, ...props } = $props();
</script>
<svelte:element this={tag} class={["text", className]} {...props}>
{@render children?.()}
</svelte:element>
<style>
.text {
color: var(--color-50);
line-height: 1.65em;
font-weight: 300;
font-size: 1rem;
font-stretch: 120%;
}
</style> Svelte will now apply the If we then decide to extend the <script>
import { Text } from "$lib/components/Text";
let { tag = "h2", fill = "gradient", class: className, children, ...props } = $props();
</script>
<Text {tag} class={["heading", className]} data-fill={fill} {...props}>
{@render children?.()}
</Text>
<style>
.heading {
font-weight: 600;
font-stretch: 151%;
text-wrap: balance;
&[data-fill="solid"] {
color: var(--color-50);
}
&[data-fill="gradient"] {
color: transparent;
background: linear-gradient(180deg, var(--color-50) 50%, var(--color-300) 80%);
background-clip: text;
-webkit-background-clip: text;
}
}
</style> Svelte will now apply the What if we tried using the
|
Describe the problem
With
@layer
baseline widely available, it is easy enough to write desired styles in vanilla CSS without the need to fight against specificity and writing order issues.I prefer writing my styles using CSS cascade layers and don't feel the need for Svelte's CSS scoping feature. I also don't like my HTML elements getting unnecessary auto-generated cryptic class names attached to them.
This has been brought to attention in past also but no activity there for long time.
Describe the proposed solution
As Svelte always prefers to embrace native web technologies over custom solutions wherever possible, there should at-least be an option in
svelte.config.js
to disable CSS scoping application wide for the users who don't want this nice to have feature.Thanks for awesome work.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: