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

[css-anchor-position] anchor-scope and part descendant styling #10525

Open
vmpstr opened this issue Jul 4, 2024 · 3 comments
Open

[css-anchor-position] anchor-scope and part descendant styling #10525

vmpstr opened this issue Jul 4, 2024 · 3 comments

Comments

@vmpstr
Copy link
Member

vmpstr commented Jul 4, 2024

anchor-scope is specified to limit the exposure of anchors to not go above the anchor-scope element. However, anchor-name are also tree scoped which means that an element that is exposed as a part and given an anchor-name that way is scoped to the tree scope of the stylesheet that gives it a name (outside of the shadow dom).

I wanted to clarify what happens if both of these features are in effect:

<style>
my-element::part(anchor) {
  anchor-name: --anchor;
}
</style>
<my-element>
  <template shadowrootmode="open">
    <div id="scoper" style="anchor-scope: all">
       <div id="anchor" part="anchor"></div>
    </div>
  </template>
</my-element>

Here the #scoper element is scoping all the anchors to its subtree, but #anchor is exposed as a part and is styled in the outer tree scope and is given an anchor-name there. Is that a valid anchor in the outer (or inner) tree scope?

/cc @andruud @tabatkins

@andruud
Copy link
Member

andruud commented Jul 4, 2024

This should be well defined now. Only anchor queries from within the flat-tree subtree of #scoper can "see" --anchor. So it's not visible in the outer scope, except when the query comes from another ::part(), e.g.:

<style>
my-element::part(anchor) {
  anchor-name: --anchor;
}
my-element::part(anchored) {
  left: anchor(--anchor right);
}
</style>
<my-element>
  <template shadowrootmode="open">
    <div id="scoper" style="anchor-scope: all">
       <div id="anchor" part="anchor"></div>
       <div id="anchored" part="anchor"></div> <!-- Works -->
    </div>
   <!-- But not if part=anchor was here instead. -->
  </template>
</my-element>
<!-- And certainly not from here. -->

(And also a similar case with a slotted element).

In the inner scope, --anchor is visible inside #scoper, but not outside it.

@vmpstr
Copy link
Member Author

vmpstr commented Jul 4, 2024

That's interesting. I suspect that may be a little unexpected for developers: using a web component that exposes an element as a part, but giving that part an anchor name and trying to anchor to it doesn't work because unbeknownst to the developer, the web component has an anchor-scope protecting the part

@andruud
Copy link
Member

andruud commented Jul 5, 2024

I am tempted to say that the web component author shouldn't have blocked all anchors if all anchors shouldn't be blocked.

If you're worried that this is a bad situation they will fall into accidentally, then we'll need to invent some kind of "tree-scoped all"?

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

No branches or pull requests

2 participants