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

inject element's styles at the end of the ShadowRoot children #12

Closed
trusktr opened this issue Apr 8, 2024 · 1 comment · Fixed by #13
Closed

inject element's styles at the end of the ShadowRoot children #12

trusktr opened this issue Apr 8, 2024 · 1 comment · Fixed by #13
Labels
enhancement New feature or request

Comments

@trusktr
Copy link
Member

trusktr commented Apr 8, 2024

otherwise the following will fail if styles are prepended:

        template = html`
            <!-- Element styles are currently prepended here. -->

            <!-- import a lib, f.e. bootstrap. -->
            <link rel="stylesheet" href="./lib.css" />

            <!-- Because lib.css ends up *after* element styles, element styles do not override lib styles. -->
            <div class="lib-btn"></div>
        `

Current workaround is to define styleRoot where styles will be appended:

        #styleRoot = document.createElement('div')

        get styleRoot() {
            return this.#styleRoot
        }

        template = html`
            <!-- import a lib, f.e. bootstrap. -->
            <link rel="stylesheet" href="./lib.css" />
            
            <!-- Element styles are prepended here in the styleRoot. -->
            ${this.styleRoot}

            <!-- Styles work as expected, element styles overrode lib styles. -->
            <div class="lib-btn"></div>
        `

PR:

@trusktr trusktr changed the title inject styles at the end of the ShadowRoot children inject element's styles at the end of the ShadowRoot children Apr 8, 2024
@trusktr
Copy link
Member Author

trusktr commented Apr 8, 2024

Related, once we implement

then the problem is solved in that case because adopted style sheets behave similar to styles appended to the end of ShadowRoot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant