Skip to content
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

Scoped global styling not working #110

Open
pikeas opened this issue Jul 15, 2022 · 2 comments
Open

Scoped global styling not working #110

pikeas opened this issue Jul 15, 2022 · 2 comments

Comments

@pikeas
Copy link

pikeas commented Jul 15, 2022

Describe the bug
Scoped global styling doesn't seem to work. Classes are being applied and the component is reactive, so the issue is specifically around style scoping.

To Reproduce

<script lang="ts">
    import MyComponent from "$lib/things/MyComponent.svelte"
</script>

<section>
    <MyComponent />
</section>

MyComponent is exactly copied from https://svelte-headlessui.goss.io/docs/general-concepts#the-global-modifier, the version using a wrapper div and * > :global(.checked).

@pikeas
Copy link
Author

pikeas commented Jul 15, 2022

I just sanity checked this with dummy components:

<script lang="ts">
    import Outer from "$lib/foo/Outer.svelte"
</script>

<Outer />
<script lang="ts">
    import Inner from "./Inner.svelte"
</script>

<div>Outer 1</div>
<div><Inner foo="inner" /></div>
<div>Outer 2</div>

<style>
    * > :global(.inner) {
        color: red;
    }
</style>
<script lang="ts">
    export let foo = ""
</script>

<div class={foo}>Inner</div>

This works as expected so svelte-headlessui is doing something funky. Maybe related to using class as the prop name?

@pikeas
Copy link
Author

pikeas commented Jul 15, 2022

The plot thickens!

For RadioGroup:

  • * > :global(label) does not work
  • * :global(label) works

For Dialog:

  • * > :global(h2) does not work
  • * :global(h2) also does not work!

Ah, just found this docs note:

This rule won’t work properly inside a portal, which means that it won’t work properly for a <Dialog>. To style the <Dialog>, you will need to either 1) use global styles without the * > scoping, 2) put a wrapper element inside the <Dialog> and style that instead, or 3) use one of the other styling approaches.

I think that explains everything I've seen. Definitely surprising!

I'll keep this open for the RadioGroup behavior - should this work with and without the descendant selector?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant