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

shadowRoot attached on DIV Element does not reset styles with all:initial #7249

Closed
Danny-Engelman opened this issue Oct 20, 2021 · 5 comments

Comments

@Danny-Engelman
Copy link

Danny-Engelman commented Oct 20, 2021

Should it be possible to reset styles with :host{ all:initial } ??

Same behavior on Chromium and FireFox:

JSFiddle: https://jsfiddle.net/WebComponents/6u1e4m3y/

<style>
  div,
  custom-element {
    color: red;
    font-weight: bold;
  }

</style>

<div id="div1" reset=":host" style="color:green"></div>
<div id="div2" reset=":host" style="all:initial"></div>
<div id="div3" reset=":host"></div>
<div id="div4" reset="div"></div>
<custom-element reset=":host"></custom-element>
<custom-element reset="div"></custom-element>

<script>
  function attachShadowRoot(el) {
    let shadow = el.attachShadow({mode: 'open'});
    let reset = el.getAttribute("reset");
    shadow.innerHTML = `<style>${reset} { all: initial; }</style><div></div>`;
    let div = shadow.querySelector("div");
    let { color } = getComputedStyle(div);
    div.innerHTML = `reset in: ${reset} color: ${color} in ${el.nodeName} id: ${el.id}`;
  }
  attachShadowRoot(div1);
  attachShadowRoot(div2);
  attachShadowRoot(div3);
  attachShadowRoot(div4);
  customElements.define("custom-element", class extends HTMLElement {
    connectedCallback() {
      attachShadowRoot(this);
    }
  })
</script>
@domenic
Copy link
Member

domenic commented Oct 20, 2021

This sounds like a browser bug, not a spec bug, so it's probably best filed on browser bug trackers, not spec bug trackers?

@Danny-Engelman
Copy link
Author

I made an update.

Looks like :host{ all:initial } does not reset styles, while declared as attribute on the host it does reset

@bathos
Copy link

bathos commented Oct 21, 2021

Which outcome above is unexpected? I'm probably missing something but it seemed like these results are consistent with the specificities of the style attribute (highest), selectors matching the host element in light dom (middle), and the :host selector in shadow (lowest).

@rniwa
Copy link

rniwa commented Oct 21, 2021

Non-important style rules inside a shadow root has a lower precedence to non-important & important style rules outside the shadow root. If you wanted to force resetting all properties on the host, it needs to be important since important style rules inside a shadow root has a higher precedence over everything else: i.e. all: initial !important.

@annevk
Copy link
Member

annevk commented Oct 22, 2021

Sounds like this is working as designed. Thanks all!

@annevk annevk closed this as completed Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants