Open sentiasa opened 6 years ago
same issue
I wanted to add focus to the first button, rather than the last. I'm using jQuery, so I added the following code:
function transferFocus(e) {
$('.swal-button').blur();
$('.swal-button--confirm').focus();
}
$(document).on('focus', '.swal-button--cancel', transferFocus);
$(document).on('focus', '.swal-button--confirm', function(e) {
$(document).off('focus', '.swal-button--cancel', transferFocus);
});
You can take the same principles and use vanilla Javascript to prevent event delegation on the focus event for your alerts.
You can switch the button focus to the other button by using the dangerMode
attribute (https://sweetalert.js.org/docs/#dangermode). There's no special option to disable all focus though unfortunately.
Maybe we should provide an onOpen
method so that people can manually manipulate the DOM when calling certain swals?
Yes this is a good idea
Is there a way to remove auto-focus after initial opening, so it doesn't highlight/focus any of the buttons?