-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Tab key not working after opening two Sweet Alert Modals in a row #127
Comments
From that example I can't really see that what you are saying is true, |
Sorry I didn't make that clear! Yes it's tabbing IN the model, but after you close the second modal, you lose the ability navigate the web page with the tab key (No modals on screen just the web page). |
I've attempted a fix at jack126guy/sweetalert@issue127. It seems to work insofar as the focus returns to the button on the page. However, it reveals another issue: You still can't tab to another button, and when you hit Enter to show the alert again, things get weird. |
Yes I attempted a similar fix to yours but with a window global variable to make sure it's an element from the website other than SweetAlert, it does focus the element on the document but the Tab key is still not working. What seems to have fixed it for now is removing the stopEventPropagation(e) in the if(keycode == 9) clause in the handleKeyDown method. But I'm guessing there are other side-effects to this... I would show you a commit but I did some other changes to the library as well that others might not want. |
So in case anyone wants a temporary fix for this bug, here's a repo I forked from this project: https://github.com/heero-yuy/sweetalert.git It works 100% for all my projects so far but I haven't tested it extensively to make sure my changes didn't break any other functionality. |
i fixed it inserting the two line of code above on the begin of the function sweetAlert or swal at the line 215, i don´t know if its the best solution, but its working for me.
|
👍 . This should get some priority. The fix by @jayquest seems to work. |
To implement the fix by @jayquest without changing the library, I used the following code: var previousWindowKeyDown = window.onkeydown; |
To expand on @amoralidad 's fix you can use this to include only once after you include the sweet alert library in your project and it will decorate the swal service so your code and the library stays unobstructed (without coding the fix above in every call) until a permanent fix is made. (function (){
var _swal = window.swal;
window.swal = function(){
var previousWindowKeyDown = window.onkeydown;
_swal.apply(this, Array.prototype.slice.call(arguments, 0));
window.onkeydown = previousWindowKeyDown;
};
})(); |
I can confirm this bug as well and the above workaround works well too! 👍 |
Yup, the workaround of @JustinWinthers works fine! |
however, it seems to f-up using escape and enter keys in the dialog |
The workaround of @amoralidad worked for me. Thanks! |
I just submitted a pull request with my solution. https://github.com/t4t5/sweetalert/pull/547 |
- [2016-04-12] `sweetalert`: [Fixed #127](t4t5/sweetalert#127 (comment)). - [2016-04-12] `sweetalert@input`: added option for input type alerts. - [2016-04-12] `SweetAlert@close`: added option for closing actual alert. - [2016-04-12] `gulp`: added gulp processing for minification and uglify.
@JustinWinthers , using your code breaks the For an example, go to Removing your function makes it work again. Any ideas on how to get rid of this behavior ? Thank you! |
@jayquest Thank you for fixing this issue. |
I tried your suggestion to fix this tabbing issue after SweetAlert opens. It fixed the issue, however I started getting this error when I try to close the Sweetalert using
This is similar to what @Eduardjs said above. Is there a way to get them working? I feel we got so close but due to this error, I had to remove your suggested code. Any help will be great. Cheers, |
The simplest possible solution based on the workaround of @JustinWinthers that I could found (without modifying the library), is to hook only into the (function (){
var close = window.swal.close;
var previousWindowKeyDown = window.onkeydown;
window.swal.close = function() {
close();
window.onkeydown = previousWindowKeyDown;
};
})(); or in my case even simpler: (function (){
var close = window.swal.close;
window.swal.close = function() {
close();
window.onkeydown = null;
};
})(); With this workaround it is now also possible to use the Enter and Escape keys in the dialog. The error messages mentioned by @Mr-Anonymous and @Eduardjs also no longer occur. |
@kosst Perfect. Thank you so much for sharing that. I tried your code and it works perfect. Thank you so much!! Cheers, |
@kosst You save my day Man, thanks |
Hello,
It seems that when the SweetAlert dialog opens another one after it's done, the tab key stops working, all other keystrokes are okay.
You can recreate this using the example on http://tristanedwards.me/sweetalert.
This one specifically:
I believe it's copying over the keystroke handling from the previous modal, specifically in the closeModal() function, this part:
Perhaps it's simply focusing on the previous modal and registering back it's keydown and onclick?
The text was updated successfully, but these errors were encountered: