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
Add inert attribute during Leave transitions #661
Comments
Applying the I checked against current Vue 2 version, and the behavior is consistent regarding event listeners still being able to trigger during the transition. |
The modal was an example. It's pretty much desirable on every element leaving DOM. If you have a list with a button (delete, edit, doesn't matter) on every row, you don't want the command to trigger when an item is animated out. Removed element can still receive focus. If you're tabbing into an element leaving the DOM, you then lose focus completely, not great. This leads me to:
I thought about it and choose not to mention it because I can't find a single scenario where it would be desirable to opt-out. That said, you could have an opt-out flag on
Sadly it's true that it's not supported everywhere, at least yet.
Maybe I'm too ignorant but can't you just add it during Why is it different than setting the css classes on target element? |
But it's not every time, that's the problem. Also, it would be easy if
I was referring to user code, not modifying in Vue Core. If you are referring to manually adding |
I can't think of a scenario where it's not the right thing (can you?), but you can add a prop Chrome/Edge/Opera support is sometimes enough. It's better than nothing. A polyfill exists but is far from trivial. I'm looking at creating a derived component that adds this in It's easy but:
|
You can enforce |
@Justineo Yes, it's probably the most important bit of Another situation where this arises is router transitions. |
Why not just disable the form elements after the first click...? |
@DinsmoreDesign In the context of elements being removed from DOM, it's not a good solution. Let's take the router transitioning to another page:
Devs think of removing an element from DOM as synchronous, so they see no need to disable it, unlike a long running op. Obviously it's not trivial and it's something that you want to handle in a generic way, at the transition level. Not page by page. |
I understand why you don't want to add code that is not supported by all browsers at this point (68% according to caniuse https://caniuse.com/#feat=mdn-api_htmlelement_inert) and there is a workaround: I can use a derived |
Should this be reconsidered now the browser support of Yes, it's really easy to add this yourself, but I'm not sure many developers will realise they should do this in almost all cases. Adding an opt-in to this behaviour on It would be even better as an opt-out, but that might be a breaking change. |
What problem does this feature solve?
Leave transitions can be a source of bugs, since developers usually consider that a removed element is not in the DOM anymore.
Consider a popup to make a purchase.
When the user click on submit, the code performs something like
showPopup = false
and through the magic of bindings the modal is removed from DOM.So after that point it's impossible to submit again and that's how devs usually think.
Now here comes the designer who says: "That popup disappearing is not pleasing, let's add a transition like fading it out."
It looks great but now my grandma is using the app. You need to know that my grandma double-clicks on everything (true story).
So she double-clicks the submit button.
The purchase is made, the modal is "closed"... but not really because now it has that nice fade-out transition.
It is likely that the second click will hit the submit button again, which the dev didn't expect, and maybe a second purchase is made.
If you use lots of transitions, it's hard and tedious to protect every interactive element from being used during a Leave transition.
A nice and easy solution is the
inert
attribute (supported in some modern browsers).Since the element is supposed to be removed from DOM, adding
inert
is the logical thing to do:What does the proposed API look like?
There is no new API surface.
I propose that when a Leave transition starts, the
inert
attribute is added to the element that is leaving the DOM; and when the transition finishes,inert
is removed (at least if it wasn't already there when the transition started).The text was updated successfully, but these errors were encountered: