Skip to content

Easy workaround to put component classes to childs (without global) #7962

Open
@dm-de

Description

@dm-de

Describe the problem

Sometimes, we need to use :global() styles
to modify child components
Otherwise, it would not work.

<div>
    <Icon class="extra" />
</div>

<style>
:global(.extra) {
    color: red;
}
</style>

Describe the proposed solution

MAGIC value $HASH
$HASH is replaced with the value (for example: svelte-urs9w7) of component hash

The code could look so:

<div>
    <Icon class="{$HASH} extra" />
</div>

<style>
.extra {
    color: red;
}
</style>

finally - Icon class turn to:
class="svelte-urs9w7 extra"

Alternatives considered

Alternative: do it automatic

Add $HASH to any child component, that use class, defined in style-block

Importance

i cannot use svelte without it

Metadata

Metadata

Assignees

No one assigned

    Labels

    cssStuff related to Svelte's built-in CSS handling

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions