Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

CSS Component Selector #7694

Copy link
Copy link
Open
Open
Copy link
@DeepDoge

Description

@DeepDoge
Issue body actions

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 or loading="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, like aspect-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

<div>
  <img />
<div/>
<a />

bar.svelte

<div>
  <Foo />
</div>
<Foo />

<style>
  div > $Foo { /* Selects `div` and `a` element in the `Foo` component, because they are in the root  */
    ...
  }
<style />

syntax can change.

Alternatives considered

An option to bind everything(attributes(class), events...) in a root element in the component.

Example:
foo.svelte

<div bind:$$root>
   <img />
<div />
<div />

bar.svelte

<Foo class="thing" on:click={() => alert()}>

<style>
.thing { /* this would only select the first `div` element in the `Foo` component
  ...
}
<style />


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

jhwz, emmnull, codepainting, OrangeBurrito, phoenisx and 2 more

Metadata

Metadata

Assignees

No one assigned

    Labels

    cssStuff related to Svelte's built-in CSS handlingStuff related to Svelte's built-in CSS handlingfeature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.