In Svelte I can pass a custom class to a children component like that:
Icon.svelte
<script>
export { className as class };
let className = '';
</script>
<img src='...' class={className} />
App.svelte
<script>
import Icon from './Icon/Icon'
</script>
<div id='app'>
<Icon class='custom-icon' />
</div>
If I inspect the rendered DOM I see that the class is successfully given to the Icon
component:
<img src='...' class='custom-icon' />
But if I define some style for .custom-icon
in App.svelte
they are not applied:
<script>
import Icon from './Icon/Icon'
</script>
<style>
.custom-icon {
border: solid 2px red;
}
</style>
<main>
<Icon class='custom-icon' /> <!-- Icon has no red border -->
</main>
Check the codesandbox.
So has someone an idea how I can style a children component from the parent using a class?