Open keithamus opened 1 year ago
Yes, it's not possible in general. The issue is that neither Transitions nor Animations recognizes the concept of state changes (entries or exits). Transitions is based purely on property changes (which'll often, but not entirely, map to a state change), while Animations run while an element is in a state. You can fake an entry animation by running the animation only once, but because it's just fakery you can't do the opposite and get an exit animation out of it. At a fundamental level, the model that T&A were defined to work on doesn't map to state changes.
So yeah we'd need to do something novel to actually solve this.
I think that with the proposed animation-trigger
you can achieve this. If I'm not mistaken, the only thing that would be missing is to define how a state can produce a timeline, and then the ranges should simply be whether the state is on/off.
I guess if the animation-delay
doesn't exactly match here we could try defining time-based ranges that expand the trigger's timeline.
Then you could define a trigger of type alternate
with a timeline of the state and you'll get the reversed animation played on exit.
The Open-UI WG proposal on
popover=hint
includes two new CSS properties:popover-show-delay
andpopover-hide-delay
. These are designed to allow a debouncing delay for showing and hiding a tooltip-style popover.In the discussion, I claimed that
popover-show-delay
is replicable today usinganimation-delay
. I have an example codepen which demonstrates the effect by using:hover
and:focus-within
to set an animation, with ananimation-delay
. This, as I understand it, negates the need for apopover-show-delay
, however I can't find a way within CSS to trigger an animation when a CSS state is "exited".Transitions might be the answer, but I can't figure out how to make the same effect with transitions. If someone can I'm happy to close this issue out!
If it's not possible with transitions, perhaps one way to resolve this is to add properties which allow defining an animation for when an element leaves a state. This might look like adding
exit-animation-*
for eachanimation-*
property.Another proposal would be to add stateful selectors such as
:hover-out
,:focus-leave
,:focus-within-leave
. These could apply to elements that were recently in their respective states, but have "recently" left. I suppose the mechanics for this would need to reason about how long these states apply for, based on the duration of any animation properties applied to them?