Pressing Escape key to dismiss on Safari causes window to scroll to bottom of page
See original GitHub issueCurrent behavior
Using Safari (v13.1.1) on Mojave (10.14.6) and also (on a completely separate Mac) the latest released versions of Mac OS and Safari, when I press the Escape key to dismiss a SweetAlert modal, it closes the modal correctly but then scrolls to the very bottom of the page.
Only seems to happen if an input is displayed (for example input: 'text'
)
There are no console messages and this behavior does not happen in Chrome or Firefox. Only Safari.
Pressing the “close” button closes the SweetAlert modal correctly without scrolling. Similarly, positive buttons do not affect the window’s scroll position.
The odd behavior seems to be prevented by clicking. At first I thought it was the act of “blurring” or unfocusing the input but then I realized that tabbing focus to the button and back to the input still causes the issue to happen when hitting Escape.
The below fiddle uses latest jQuery at the time of writing (3.5.1) and latest SweetAlert2 at the time of writing (10.6.1).
Expected behavior
Not the above. Window should not scroll on pressing Escape to dismiss.
Live demo
https://jsfiddle.net/twistedpixel/e6ktzL51/
Edit 1: add video demonstrating the issue: Dropbox link
Issue Analytics
- State:
- Created 3 years ago
- Comments:25 (15 by maintainers)
Quick update @limonte, I gave up fixing it in
renderInput.js
because the workaround works well only withinput: text
. For the other types, a different character need to be used (and I wasn’t able to find the correct one forpassword
).So I went back to debugging the issue and that’s what i found so far. The issue is reproduced when you have all of the following conditions:
<head>
of the page<div>
withrole="dialog"
andaria-modal="true"
within a<div>
with absolute position.<input>
inside the above<div>
I created a sample page with no Swal code here: https://nutritious-gem-order.glitch.me. In order to reproduce the issue:
I’ll start from here to see if there is a way to fix it. I tried already removing the
role
andaria-modal
from swal, but the issue is still reproduced. So there must be something else. @twistedpixel if you can five a try with the page I sent above, that’d confirm I don’t have any gremlins in my safari.@twistedpixel I don’t have a workaround / fix yet, but I have a better workaround you can apply to you code and avoid creating a container. The point here is to create a mixin that uses
didOpen
to change the value of the input (twice).Have a go and let me know if this is solving (at least temporarily) your issue.