Skip to content

Instantly share code, notes, and snippets.

@happyboredom
Created January 4, 2012 19:10
Show Gist options
  • Save happyboredom/1561512 to your computer and use it in GitHub Desktop.
Save happyboredom/1561512 to your computer and use it in GitHub Desktop.
Prevent jQueryUI dialog from setting focus on links or form fields
$(selector).dialog({
open: function (evt, ui) {
$(':focus', this).blur();
},
width:400,
height:250,
modal:true,
title:'Help'
});
@happyboredom
Copy link
Author

I started with :tabbable selector but I think that it is only available in jqueryUI. The :focus selector is part of regulary jQuery and works just as well.

@mattbrundage
Copy link

UI Dialog checks for focus when the [Esc] key is pressed and will only close the dialog at that time if it has focus. You're better off retaining dialog focus, but removing focus styles (outline, etc) in your CSS.

@caot
Copy link

caot commented Aug 26, 2019

Just ran into the case and landed at the link. Added the follows to fix.

.ui-dialog :focus {
outline: -webkit-focus-ring-color auto 0px !important;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment