w3ctag / design-reviews

W3C specs and API reviews
Creative Commons Zero v1.0 Universal
328 stars 55 forks source link

View Transition Classes #938

Open vmpstr opened 7 months ago

vmpstr commented 7 months ago

こんにちは TAG-さん!

I'm requesting a TAG review of View Transition Classes.

This feature introduces a new CSS property view-transition-class which allows the developer to specify one or more view transition classes. The developer can then select the ViewTransition pseudo elements using these classes (e.g. ::view-transition-group(*.class)).

This is an extension to the ViewTransition API that simplifies styling of view transition pseudo elements in a similar way that CSS classes simplify styling of regular DOM elements.

Further details:

We'd prefer the TAG provide feedback as:

🐛 open issues in our GitHub repo for each point of feedback: https://github.com/w3c/csswg-drafts/issues with css-view-transitions-2 label.

plinss commented 1 month ago

Thanks for bearing with us. After reviewing and discussing internally, we have one question which is: did you discuss the option of using selectors and if so could you document in the explainer the reasoning for not using that approach?

We see the extra layer of indirection as being useful if view transitions can be used with multiple arbitrary pages, but it's unclear if the transitions will be generic enough in general to be reused. If the transitions need to be tailored to the specific page content then an extra layer of indirection doesn't seem useful.

noamr commented 1 month ago

Thanks for bearing with us.

Thanks for getting to it!

After reviewing and discussing internally, we have one question which is: did you discuss the option of using selectors and if so could you document in the explainer the reasoning for not using that approach?

Can you explain what this approach is? Happy to add to the explainer but I need to understand what that means first :)

plinss commented 1 month ago

Rather than defining a new kind of class, simply using a normal selector (or selector list) within the pseudo-element, e.g. ::view-transition-group(<selector>)

noamr commented 1 month ago

Rather than defining a new kind of class, simply using a normal selector (or selector list) within the pseudo-element, e.g. ::view-transition-group(<selector>)

That is what we are doing though

::view-transition-group(.class-name) where the class is given by the participating element using the `view-transition-class' property.

plinss commented 1 month ago

Your '.class-name' example isn't a regular class though, it's a view-transition-class (in which case I object to using the class syntax as it's confusing to authors, you're conflating the concept of class), what we're referring to is just using a regular class, or an Id, or any other kind of selector.

e.g.: Instead of:

div.thing1, div.thing2 { view-transition-class: my-transition }
::view-transition-group(.my-transition)

just use:

::view-transition-group(div.thing1, div.thing2)
noamr commented 1 month ago

Your '.class-name' example isn't a regular class though, it's a view-transition-class (in which case I object to using the class syntax as it's confusing to authors, you're conflating the concept of class), what we're referring to is just using a regular class, or an Id, or any other kind of selector.

e.g.: Instead of:

div.thing1, div.thing2 { view-transition-class: my-transition }
::view-transition-group(.my-transition)

just use:

::view-transition-group(div.thing1, div.thing2)

Ah that's not viable because for exit transitions the selector is invalid by the time the view transition starts. When @vmpstr is back from leave we'll update the explainer.

plinss commented 1 month ago

I don't understand that point, if a regular selector is invalid by the time the view transition starts, then wouldn't the selector that assigns the view transition class be invalid too?

noamr commented 1 month ago

I don't understand that point, if a regular selector is invalid by the time the view transition starts, then wouldn't the selector that assigns the view transition class be invalid too?

No! That's how view transitions work. You capture the old state, change the DOM in whatever way you want (including removing elements), capture the new state, and then run the animation. There is no guarantee that the original state of the DOM (and thus the selectors) remains valid by the time you start the animation. The tether that connects everything is the CSS properties like view-transition-name and view-transition-class that are carried over to the view transitions.

plinss commented 1 month ago

Right, so if you're capturing the names and classes before the transition, can't you just capture the view transition groups instead?

plinss commented 1 month ago

Also, have you considered simply allowing a list of view transition names in the view-transition-group selector, e.g. instead of:

::view-transition-group(list-item-1),
::view-transition-group(list-item-2),
::view-transition-group(list-item-3),
::view-transition-group(list-item-4),
::view-transition-group(list-item-5),
::view-transition-group(list-item-6),
::view-transition-group(list-item-7) {
  background: green;
}

do:


::view-transition-group(list-item-1, list-item-2, list-item-3, list-item-4, list-item-5, list-item-6, list-item-7) {
  background: green;
}```
noamr commented 1 month ago

Right, so if you're capturing the names and classes before the transition, can't you just capture the view transition groups instead?

You mean reading the pseudo-element styles ahead of time? Note that between the old and new document we might be changing documents, or other state might change.

e.g. html.some-state::view-transition-group(*) might be matched before the transition and not match during the transition (e.g. you call document.documentElement.classList.remove("some-state")) before the transition starts.

A lot of the current design of view transitions is based on the notion that the pseudo-elements are only created when the transition starts, we didn't want to break it for view-transition-class.

Also, have you considered simply allowing a list of view transition names in the view-transition-group selector, e.g. instead of:

::view-transition-group(list-item-1),
::view-transition-group(list-item-2),
::view-transition-group(list-item-3),
::view-transition-group(list-item-4),
::view-transition-group(list-item-5),
::view-transition-group(list-item-6),
::view-transition-group(list-item-7) {
  background: green;
}

do:

::view-transition-group(list-item-1, list-item-2, list-item-3, list-item-4, list-item-5, list-item-6, list-item-7) {
  background: green;
}```

This seems error prone when weighing against

li { view-transition-class: list-item } 

For the same reason we don't replace ordinary classes with #id1, #id2, #id3 we don't want to do that here.

vmpstr commented 1 month ago

I think Noam covered most of our reasons here.

I'd just like to highlight that the view-transition-name and view-transition-class are somewhat analogous to id and class in html. However, because it's set in CSS it allows us to add this property easier in some situations without requiring attribute changes. For example,

.container > div {
  view-transition-class: container-item;
}

this isn't as ergonomic if you require that the divs within the container have a common class specified on them. It may be common that this is already the case, but coupling view transitions with existing classes seems more restrictive in general.