Skip to content

[css-anchor-position-1] Reusing the implicit anchor name on the nested elements #8913

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

Closed
kizu opened this issue Jun 3, 2023 · 7 comments
Closed

Comments

@kizu
Copy link
Member

kizu commented Jun 3, 2023

We currently can use the implicit anchor element provided by the anchor attribute associated with some id. This would be mainly used for popovers (though, at least the current implementation in Chrome Canary allows this attribute and its implicit anchor on any element).

The issue is: we currently seem to only be able to use this implicit anchor on the element itself, but we don't have access to it in any other way?

What we could want is to somehow access this anchor from elements or pseudo-elements nested inside our popover (or another element with anchor on it). This can be useful when we'd want to use this element as the tooltip arrow or another connector that should span from the popover's anchor to the popover itself.

Here is an implementation of how this should work: https://codepen.io/kizu/pen/qBJQpjm?editors=1100 — using both the anchor attribute, and the explicitly set anchor-names.

(note that there is currently a bug where we have to use the anchor attribute even if we do not use the implicit anchor and override it with the anchor-default — https://bugs.chromium.org/p/chromium/issues/detail?id=1451095)

In the example above we'd want to have an element that is nested inside the popover and which spans from it to the button it is anchored with via an anchor attribute.

If we'd use an additional element, we could add the same anchor attribute, but that would mean duplicating things.

Some ideas of possible solutions:

  • When we define the implicit anchor, make it somehow inherit to all the elements inside?
  • Introduce a new value for the anchor-element?
  • Something else?
@xiaochengh
Copy link
Contributor

xiaochengh commented Jun 13, 2023

An easy fix, at least for your use case, would be saying a ::before or ::after pseudo element (which are the only pseudo elements that can create an OOF box, I suppose?) has the same implicit anchor element as the originating element.


Or if we want any child element to be able to use its parent's implicit anchor, then this may be solved by @tabatkins's proposal in #8181

The proposal says whenever we have an anchor element reference (either by implicit anchor, anchor-default or an anchor name), its computed value should be the actual anchor element instead of just a name.

Then we can do something like

.parent { anchor-default: implicit; } /* This should compute to the implicit anchor element */
.child { anchor-default: inherit; } /* Inherits the parent element's implicit anchor element */

@kizu
Copy link
Member Author

kizu commented Jun 13, 2023

I like the idea of a ::before and ::after having the same implicit originating element. Given that very often we could want to use those elements for things like popover arrows, it would be useful.

Though, in some cases we could want a more complicated structure, where we would have to use an actual extra element. In that case the proposal which would make the inherit getting the actual element from the parent sounds even better, and could be also used for the pseudo-elements.

@tabatkins
Copy link
Member

Or if we want any child element to be able to use its parent's implicit anchor, then this may be solved by @tabatkins's proposal in #8181

Oooh yeah, that would work for a general solution, interesting. I think you pushed back on #8181 earlier for impl reasons - any new thoughts?

a ::before or ::after pseudo element (which are the only pseudo elements that can create an OOF box, I suppose?) has the same implicit anchor element as the originating element.

This is a pretty good narrow solution, tho. This feels like it should be pretty straightforward, so I'll just add it.

@xiaochengh
Copy link
Contributor

I think you pushed back on #8181 earlier for impl reasons - any new thoughts?

Still really hard to implement.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jun 17, 2023
…nt's implicit anchor

See w3c/csswg-drafts#8913 for more details.

Fixed: 1455563
Change-Id: I8e37ff58bb77f1850e46c88d9ff66cc0bb58bca8
@kizu
Copy link
Member Author

kizu commented Jun 19, 2023

In the OpenUI discord there was a question by @o-t-w about a certain common use case for the ::backdrop:

One UX feature that has become pretty common in the last few years is product tours - either as part of onboarding users to the product or to highlight new features to established users. Often in this pattern the rest of the page is dimmed as focus is drawn to one element of the UI. Popovers and anchor positioning would be useful here but using ::backdrop probably couldn't be made to work for this use case? Curious how people would approach this.
Screenshot showing a feature highlight popover with a backdrop looking like a spotlight, highlighting the element the popover is anchored to.

I tested it, and managed to re-create this effect with a ::backdrop and anchor positioning (https://codepen.io/kizu/pen/zYMBwNQ?editors=1100), however, it seems that we should also allow the ::backdrop to use the originating element as well as an implicit anchor, as it would make it possible to then use it for similar use cases much more conveniently.

aarongable pushed a commit to chromium/chromium that referenced this issue Jun 20, 2023
…nt's implicit anchor

See w3c/csswg-drafts#8913 for more details.

Fixed: 1455563
Change-Id: I8e37ff58bb77f1850e46c88d9ff66cc0bb58bca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4622093
Reviewed-by: Joey Arhar <[email protected]>
Commit-Queue: Xiaocheng Hu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1160220}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jun 20, 2023
…nt's implicit anchor

See w3c/csswg-drafts#8913 for more details.

Fixed: 1455563
Change-Id: I8e37ff58bb77f1850e46c88d9ff66cc0bb58bca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4622093
Reviewed-by: Joey Arhar <[email protected]>
Commit-Queue: Xiaocheng Hu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1160220}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jun 20, 2023
…nt's implicit anchor

See w3c/csswg-drafts#8913 for more details.

Fixed: 1455563
Change-Id: I8e37ff58bb77f1850e46c88d9ff66cc0bb58bca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4622093
Reviewed-by: Joey Arhar <[email protected]>
Commit-Queue: Xiaocheng Hu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1160220}
@xiaochengh
Copy link
Contributor

^ Adding ::backdrop sounds reasonable to me

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jun 28, 2023
…fter to use originating element's implicit anchor, a=testonly

Automatic update from web-platform-tests
[anchor-position] Allow ::before and ::after to use originating element's implicit anchor

See w3c/csswg-drafts#8913 for more details.

Fixed: 1455563
Change-Id: I8e37ff58bb77f1850e46c88d9ff66cc0bb58bca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4622093
Reviewed-by: Joey Arhar <[email protected]>
Commit-Queue: Xiaocheng Hu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1160220}

--

wpt-commits: 1a07e5d0574ee0158eb5e854ee90174c3c98bbe1
wpt-pr: 40608
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Jul 1, 2023
…fter to use originating element's implicit anchor, a=testonly

Automatic update from web-platform-tests
[anchor-position] Allow ::before and ::after to use originating element's implicit anchor

See w3c/csswg-drafts#8913 for more details.

Fixed: 1455563
Change-Id: I8e37ff58bb77f1850e46c88d9ff66cc0bb58bca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4622093
Reviewed-by: Joey Arhar <jarharchromium.org>
Commit-Queue: Xiaocheng Hu <xiaochenghchromium.org>
Cr-Commit-Position: refs/heads/main{#1160220}

--

wpt-commits: 1a07e5d0574ee0158eb5e854ee90174c3c98bbe1
wpt-pr: 40608

UltraBlame original commit: 314d383374dff8b8fd44762576b52e25caac3c2a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Jul 1, 2023
…fter to use originating element's implicit anchor, a=testonly

Automatic update from web-platform-tests
[anchor-position] Allow ::before and ::after to use originating element's implicit anchor

See w3c/csswg-drafts#8913 for more details.

Fixed: 1455563
Change-Id: I8e37ff58bb77f1850e46c88d9ff66cc0bb58bca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4622093
Reviewed-by: Joey Arhar <jarharchromium.org>
Commit-Queue: Xiaocheng Hu <xiaochenghchromium.org>
Cr-Commit-Position: refs/heads/main{#1160220}

--

wpt-commits: 1a07e5d0574ee0158eb5e854ee90174c3c98bbe1
wpt-pr: 40608

UltraBlame original commit: 314d383374dff8b8fd44762576b52e25caac3c2a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Jul 1, 2023
…fter to use originating element's implicit anchor, a=testonly

Automatic update from web-platform-tests
[anchor-position] Allow ::before and ::after to use originating element's implicit anchor

See w3c/csswg-drafts#8913 for more details.

Fixed: 1455563
Change-Id: I8e37ff58bb77f1850e46c88d9ff66cc0bb58bca8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4622093
Reviewed-by: Joey Arhar <jarharchromium.org>
Commit-Queue: Xiaocheng Hu <xiaochenghchromium.org>
Cr-Commit-Position: refs/heads/main{#1160220}

--

wpt-commits: 1a07e5d0574ee0158eb5e854ee90174c3c98bbe1
wpt-pr: 40608

UltraBlame original commit: 314d383374dff8b8fd44762576b52e25caac3c2a
@kizu kizu changed the title [css-anchor-1] Reusing the implicit anchor name on the nested elements [css-anchor-position-1] Reusing the implicit anchor name on the nested elements Nov 25, 2023
@tabatkins
Copy link
Member

(Reviewed this with Elika today, we're both good with it.)

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

3 participants