]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Don't blur focused tab on sort
authorScott González <scott.gonzalez@gmail.com>
Wed, 12 Oct 2016 16:21:01 +0000 (12:21 -0400)
committerScott González <scott.gonzalez@gmail.com>
Wed, 12 Oct 2016 17:14:28 +0000 (13:14 -0400)
Fixes #14627
Closes gh-1761

demos/tabs/sortable.html

index 051663ed4e9835b451126745e78150c78d0e18a3..9888cff771e78e3d58766de711a0fc86895bdcd4 100644 (file)
@@ -9,10 +9,21 @@
        <script src="../../external/requirejs/require.js"></script>
        <script src="../bootstrap.js" data-modules="sortable">
                var tabs = $( "#tabs" ).tabs();
+               var previouslyFocused = false;
+
                tabs.find( ".ui-tabs-nav" ).sortable({
                        axis: "x",
-                       stop: function() {
+
+                       // Sortable removes focus, so we need to restore it if the tab was focused
+                       // prior to sorting
+                       start: function(event, ui) {
+                               previouslyFocused = document.activeElement === ui.item[ 0 ];
+                       },
+                       stop: function(event, ui) {
                                tabs.tabs( "refresh" );
+                               if (previouslyFocused) {
+                                       ui.item.focus();
+                               }
                        }
                });
        </script>