-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
CSS Component Selector #7694
Comments
I was thinking and, or maybe something like: div > :$Foo {
...
}
div > :$Foo(div) {
...
} Also can be used like div > :$Foo(div > img) {
...
} which lets you use the selectors inside the component's scope |
Having a way to target components with CSS would be awesome. There must be existing proposals or discussions that have touched on this but for me personally this would be a great quality of life improvement, saves having to make classes and pass those down. As a start, you could have it only work on components that have a single, top-level HTML element in them (so in your case the |
tbh so in theory to select the first top element you can do tricks like so as i said similar to |
I proposed a different Component selector approach in #6972 (comment), and even created a POC svelte-preprocessor that allows you to use the approach today! 😄 |
Describe the problem
It's a common thing using components to have personalized HTML elements.
For example
<img />
element, i can make a<Image>
component that uses<picture>
by default orloading="lazy"
attribute. So it's easier to re-use or change.The problem is its still common to add custom styles to image element, like
background-color
object-fit
and many other stuff, likeaspect-ratio
,width
etc.Svelte components doesn't allow that unless you make somehow
:global()
hacks. Which doesn't give warnings when invalid and looks hacky. And when you not try to use:global()
it becomes even more hacky and makes you use a lot of boilerplate code.Describe the proposed solution
A CSS component selector to select all of the root elements in the component.
Example:
foo.svelte
bar.svelte
syntax can change.
Alternatives considered
An option to bind everything(attributes(class), events...) in a root element in the component.
Example:
foo.svelte
bar.svelte
if none of these are applicable at least having a way to bind/pass/inherit all of the events would be cool.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: