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-transitions-2] Add spec for @starting-style #8174 #8876

Merged
merged 6 commits into from
Jun 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 53 additions & 23 deletions css-transitions-2/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,38 @@ transition's <dfn>transition generation</dfn>.

## Defining [=before-change style=]: the ''@starting-style'' rule

Transitions can only start during a [=style change event=] for elements which
has a defined [=before-change style=] established by the previous
[=style change event=], which means that newly inserted elements or elements
that change from not [=being rendered=] to being rendered do not start
transitions. Still, doing transitions starting from the initial rendering is a
valid use case.
In Level 1 of this specification, transitions can only start during a
[=style change event=] for elements which have a defined [=before-change style=]
established by the previous [=style change event=]. That means a transition
could not be started on an element that was not being rendered for the previous
[=style change event=] (see: [[css-transitions-1#starting]]).

In some cases it makes sense to start transitions on newly inserted elements or
elements that change from not [=being rendered=] to being rendered. To allow
for that, this specification introduces ''@starting-style''.

The <dfn at-rule id="at-ruledef-starting-style">@starting-style</dfn> rule is a
conditional group rule with the implicit condition that it matches if the
previous [=style change event=] did not establish a [=before-change style=] for
the element whose styles are being computed. This is used to establish a
grouping rule where the rules inside it apply if the previous
[=style change event=] did not establish a [=before-change style=] for the
element whose styles are being computed. This is used to establish a
[=before-change style=] for the current [=style change event=].
lilles marked this conversation as resolved.
Show resolved Hide resolved

If any rules in ''@starting-style'' are applied, the resulting style must be
used as the [=before-change style=] for the current [=style change event=] and
the computed styles must be re-computed without ''@starting-style'' rules
applied.
Note that this means that ''@starting-style'' rules only applies to some
lilles marked this conversation as resolved.
Show resolved Hide resolved
elements during a computed style update, namely elements that were not rendered
or part of the DOM during the previous [=style change event=].

If any style rules in ''@starting-style'' are applied, the resulting style must
be used as the [=before-change style=] for the current [=style change event=].
dbaron marked this conversation as resolved.
Show resolved Hide resolved
lilles marked this conversation as resolved.
Show resolved Hide resolved
Style rules in ''@starting-style'' do not apply directly to
lilles marked this conversation as resolved.
Show resolved Hide resolved
[=after-change style=].

<div class="note">
Since ''@starting-style'' is applied to create a [=before-change style=] during
the same [=style change event=] as it is being used for triggering
transitions, it inherits from the parent element's [=after-change style=], even
lilles marked this conversation as resolved.
Show resolved Hide resolved
if the parent establishes a [=before-change style=] through
''@starting-style''.
</div>

<div class=example>

Expand Down Expand Up @@ -217,27 +232,42 @@ applied.
</pre>
</div>
dbaron marked this conversation as resolved.
Show resolved Hide resolved

<div class=example>

Transitioning an element with opacity in and out of display:none:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be useful to have a few sentences of explanation on why there are two display: none; opacity: 0; pieces and what each one does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized display:none in the starting style was actually wrong. Corrected and commented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but I think it's probably still worth explaining what the two opacity: 0 declarations do -- and how one of them applies to the transition when class=hidden is removed and the other applies to the transition when class=hidden is added.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort of tried to do that already, and I've modified the description a bit, but I'm not quite sure how you'd want it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, mostly looks good, but I left a few comments.

lilles marked this conversation as resolved.
Show resolved Hide resolved

<pre class=lang-css>
#target {
transition-property: opacity, display;
transition-duration: 0.5s;
display: block;
opacity: 1;
@starting-style {
display: none;
opacity: 0;
}
}
#target.hidden {
display: none;
opacity: 0;
}
</pre>
</div>

Global, name-defining at-rules such as ''@keyframes'', ''@font-face'', and
''@layer'' are not constrained by ''@starting-style''.
''@layer'' are allowed inside ''@starting-style'', and when present behave as
if they were outside of ''@starting-style''.

### The <code>CSSStartingStyleRule</code> interface

The {{CSSStartingStyleRule}} interface represents a ''@starting-style'' rule.

<pre class='idl'>
[Exposed=Window]
interface CSSStartingStyleRule : CSSConditionRule {
interface CSSStartingStyleRule : CSSGroupingRule {
};
</pre>

<dl class='idl-attributes'>
<dt><code>conditionText</code> of type <code>CSSOMString</code>
(CSSStartingStyle-specific definition for attribute on CSSConditionRule)
<dd>The <code>conditionText</code> attribute (defined on the
<code>CSSConditionRule</code> parent rule), on getting, must return the
empty string.
</dl>


# Application of transitions # {#application}

Expand Down