I put together a small dialog web component to experiment with View Transitions, and I’ve run into a behaviour I don’t understand.
All browsers support closing a <dialog> via the esc key, which triggers a cancel event. If I open one dialog, then open a second dialog on top of it, pressing esc key closes the most recently opened dialog and the View Transition runs as expected. However, pressing escape again to close the underlying dialog no longer triggers the View Transition.
If I add an explicit keydown event listener, the View Transition works as expected. Admittedly this is my first time dabbling with View Transitions but am i missing something obvious?
Yes I can see that behaviour but don’t know enough about it to say whether its a bug or not. If you nested more elements you would see that it fails on every second escape. Your keydown handler seems to be a suitable fix.
I agree it seems overcomplicated. What you are seeing is a stripped back attempt at animating out dialogs as right now it doesn’t work in Firefox. This is purely for learning. Once animations are working across all browsers I may add some slots and custom events etc.