Skip to content

Commit 0ab99f3

Browse files
noamrkhushalsagar
andauthored
[css-view-transitions-2] Allow auto as a keyword (#10922)
* [css-view-transitions-2] Allow `auto` as a keyword `auto` resolves to either the element's ID, or to a unique identifier that is stable for the duration of the transition and is not web-observable. Resolution: #8320 (comment) Closes #8320 * Fix refs * Tighten definition of unique string * Update css-view-transitions-2/Overview.bs Co-authored-by: Khushal Sagar <63884798+khushalsagar@users.noreply.github.com> * Handle scoping * Change scoping text * Change scoping text * Update Overview.bs Co-authored-by: Khushal Sagar <63884798+khushalsagar@users.noreply.github.com> --------- Co-authored-by: Khushal Sagar <63884798+khushalsagar@users.noreply.github.com>
1 parent 5f1b63c commit 0ab99f3

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

css-view-transitions-2/Overview.bs

+68
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,72 @@ div.box {
753753
1. Return |viewTransition|.
754754
</div>
755755

756+
# Determining 'view-transition-name' automatically # {#auto-vt-name}
757+
758+
## Overview ## {#auto-vt-name-overview}
759+
760+
*This section is non-normative.*
761+
762+
For an element to participate in a view transition, it needs to receive a unique 'view-transition-name'.
763+
This can be tedious and verbose when multiple elements are involved in the same view transition, especially in cases where many of those are same-element transitions,
764+
as in, the element has the same 'view-transition-name' in the old and new state.
765+
766+
To make this easier, setting the 'view-transition-name' to ''view-transition-name/auto'' would generate a 'view-transition-name' for the element, or take it from the element's [=Element/id=] if present.
767+
768+
## Examples ## {#auto-vt-name-example}
769+
770+
<div class="example">
771+
In this example, view transition is used to sort a list in an animated way:
772+
773+
```html
774+
<ul>
775+
<li>Item 1</li>
776+
<li>Item 2</li>
777+
<li>Item 3</li>
778+
<li>Item 4</li>
779+
...
780+
</ul>
781+
```
782+
783+
Ordinarily, each of these items would have to receive a unique 'view-transition-name':
784+
785+
```css
786+
li:nth-child(1) { view-transition-name: item1; }
787+
li:nth-child(2) { view-transition-name: item1; }
788+
li:nth-child(3) { view-transition-name: item1; }
789+
li:nth-child(4) { view-transition-name: item1; }
790+
...
791+
```
792+
793+
With ''view-transition-name/auto'', this CSS would work:
794+
795+
```css
796+
li {
797+
view-transition-name: auto;
798+
}
799+
```
800+
</div>
801+
802+
## Additions to 'view-transition-name' ## {#additions-to-vt-name}
803+
804+
In addition to the existing values, the 'view-transition-name' also accepts an <dfn for=view-transition-name type=value export>auto</dfn> keyword.
805+
To resolve the [=used value=] of 'view-transition-name' for |element|:
806+
1. Let |computed| be the [=computed value=] of 'view-transition-name'.
807+
1. If |computed| is <css>none</css>, return null.
808+
1. If |computed| is a <<custom-ident>>, return |computed|.
809+
1. Assert: |computed| is <css>auto</css>.
810+
1. If |element| has an associated [=Element/id=], and |computed| is associated with the same [=tree/root=] as |element|'s [=tree/root=], then return the value of |element|'s [=Element/id=].
811+
812+
Note: this means that a ''::part()'' pseudo-element wouldn't resolve to its matching element's [=Element/id=].
813+
814+
1. Return a unique string. The string should remain consistent and unique for this element and {{Document}}, at least for the lifetime of |element|'s [=node document=]'s [=active view transition=].
815+
816+
Note: this string is not web-observable, and is used for addressing the element in internal algorithms.
817+
818+
Note: When used in a cross-document view transition, generated <css>auto</css> values never match, resulting in separate ''::view-transition-group()'' pseudo-elements, one exiting and one entering.
819+
820+
A 'view-transition-name' generated by <css>auto</css> is a [=tree-scoped name=].
821+
756822
# Nested view-transitions # {#nested-view-transitions}
757823

758824
## Overview ## {#nested-overview}
@@ -1170,6 +1236,8 @@ When [[css-view-transitions-1#style-transition-pseudo-elements-algorithm|updatin
11701236
1. [=Multiply=] |transform| by the inverse matrix of |groupContainerElement|'s [=transform from snapshot containing block=].
11711237
</div>
11721238

1239+
1240+
11731241
<h2 id="priv" class="no-num">Privacy Considerations</h2>
11741242

11751243
This specification introduces no new privacy considerations.

0 commit comments

Comments
 (0)