-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Keyboard navigation is broken when swal is called inside a bootstrap modal #1067
Comments
bootstrap locks focus to only elements inside the modal, so using And seconds issue is regarding esc key, swal should stop propagation. |
This should be the way to handle keydown document.addEventListener('keydown', function(e){
//if esc
e.preventDefault();
e.stopPropagation();
}, true); //use capture so it triggers before bootstrap Is there any good reason for sweetalert2 to use the old I would open a PR, but I tried to reason about the project structure and I don't even know where to start... at least I couldn't figure out any straightforward life cycle phases like init and destroy, that events are registered and teared down |
Duplicate of #374 Check out #374 (comment) for the solution: $('#myModal').on('shown.bs.modal', function() {
$(document).off('focusin.modal');
}); Here's the fixed jsfiddle: https://jsfiddle.net/c1eyd94v/1/ |
Not really a solution, because that allows user to focus on elements that are unreachable. Anyway what about the ESC issue? do you want me o open a new issue just for that? |
Nice jsfiddle, thanks! Reopening the issue.
That would be nice, please follow the issue template - it's there for a reason. |
Hello @victornpb Esc propagation has been fixed, I just released 7.20.8. Also, I made the keydown handler work in capture mode, but it didn't help. I guess Bootstrap is doing something bad in the |
The fix for this broke custom elements (javascript based autocomplete input fields, etc) within the content portion of the sweetalert. Potential fix would be to allow events for targets within the content of the swal:
|
Apologies for missing your comment @infoeon, the same issue has been reported in #1130 and I fixed it today.
|
Use this code to put the focus on 'ok' button or your defined button to close the sweetalert popup.
|
When you launch it from within a bootstrap modal, it is not possible to focus the buttons, so enter or tab doesn't work.
Also pressing esc dismisses both the alert and the modal.
https://jsfiddle.net/Victornpb/c1eyd94v/
I understand that this is caused by the way bootstrap handles focus and keypresses, but considering how widespread bootstrap is compatibility is kinda expected.
The text was updated successfully, but these errors were encountered: