-
Notifications
You must be signed in to change notification settings - Fork 6.7k
modal: If something within a modal gets itself the focus then that focus is lost after the animations finish. #4903
Comments
@arkarkark, when you say "selectively gets the focus" do you mean that you are setting the focus programmatically? If so, where does that code live? If not, what is your focus expectation? The Please let us know. Thanks. |
Hi @icfantv thanks for the quick reply. Let's say my modal is an item picker - if there are no items I want the focus to be on the 'create new item' button but if there are items I want the focus to be on the select where I can choose one. I can't use autofocus attribute for this. but I can use a focus-when directive that looks at its attribute and if it's true gives the element focus. That all happens as the modal is rendering, then it finishes as this code I wrapped in an if block steals the focus and gives it to the modal div. I can imagine many other situations where I'm using components where I can't get the element I want to have focus to have an autofocus attribute, but I can programmatically find it and call focus() on it. It's interesting that you mention the rendered promise, because even that isn't good enough anymore, because the focus isn't stolen until after the animation promise is resolved which is after the rendered promise is resolved (I was going to submit a PR to fix that too). There's no way outside of the modal to know when the animation promise is finished so even if you have no css animations, you still need to wrap your callback to the rendered promise in a $timeout to get it past the animation promise. But using the rendered promise (even if it worked properly) or some surfaced animationComplete promise is much more frustrating for someone who only deals with the modal templates - right now they can use directives to say 'this' should have focus if these conditions are met. But if we're forced to use rendered we need to throw some rendered variable on the scope and wait until that becomes true before doing our logic. more watches, more focus flickering (which the comment near the modified code appears to indicate is very bad on mobile w.r.t. on screen keyboards). |
@arkarkark, I freely admit that animations are not my strong suit, but my cursory searching indicates that there are animation events for which you can listen to determine when the animation has completed. I'd have to do some more research here but am wondering if this is an impossible-to-solve race condition and whether or not some of these things will happen in a non-deterministic fashion due to browser/computer/network speed. |
I think the short of it is. If something in the modal already has focus, why steal it away? |
Without looking at our code, I can't say if we are or are not. If we are, we may have a reason (and perhaps it was an unintended side affect of another fix). |
It seems to not properly work on Internet Explorer. |
If you have directives inside your modal content that selectively get the focus then all that is lost when the modal finishes loading. (this is a regression somewhere between v0.12.1 and v0.14.2).
The text was updated successfully, but these errors were encountered: