Disable jquery-ui default behavior when using keyboard navigation

I use jquery-ui and jeditable tabs for inline editing of the tab title. But moving with the cursors in the edited text causes jquery-ui to go to the tab next to it.

How can I prevent jquery default behavior (disable tab keyword navigation).

Cheers, Broncko

+5
source share
4 answers

Solved it:

$.widget( "ui.tabs", $.ui.tabs, {
    options: {
      keyboard: true
    },
    _tabKeydown: function(e) {
      if(this.options.keyboard) {
        this._super( '_tabKeydown' );
      } else {
        return false;
      }
    }
});
+3
source

The best solution is from here http://www.daveoncode.com/2013/09/18/how-to-disable-keyboard-navigation-in-jquery-ui-tabs/ :

jQuery('.foo').tabs({
activate: function(e, ui) {
    e.currentTarget.blur();
    }
});
+2
source

keydown :

$('#tabs').tabs({
  create : function() {
    var data = $(this).data('tabs');

    data.tabs.add(data.panels).off('keydown');
  }
});
+1

. , :

$.widget("ui.tabs", $.ui.tabs, {
    _tabKeydown: function (event) {
        if (event.keyCode !== 38 && event.keyCode !== 40) {
            this._super(event);
        }
    }
});

event.keyCode - :

$.widget("ui.tabs", $.ui.tabs, {
    options: {
        overrideKeyCodes: [],
    },
    _tabKeydown: function (event) {
        var isOverride = false;
        if (Object.prototype.toString.call(this.options.overrideKeyCodes) === '[object Array]') {
            for (i = 0; i < this.options.overrideKeyCodes.length; i++) {
                if (event.keyCode === this.options.overrideKeyCodes[i]) {
                    isOverride = true;
                    break;
                }
            }
        }

        if (!isOverride) {
            this._super(event);
        }
    }
});

$('#MyTabs').tabs({ overrideKeyCodes: [ 38, 40 ] });

Or even better, you can add your own behavior:

$.widget("ui.tabs", $.ui.tabs, {
    options: {
        overrideKeyCodes: {},
    },
    tabKeydown: function (event) {
        if (this.options.overrideKeyCodes.hasOwnProperty(event.keyCode)) {
            if (typeof this.options.overrideKeyCodes[event.keyCode] === 'function') {
                 this.options.overrideKeyCodes[event.keyCode](event, this._super(event));
            }
        }
        else {
            this._super(event);
        }
    }
});

$('#MyTabs').tabs({
    overrideKeyCodes: {
        40: function (event, callback) {
            console.log(event.keyCode);
        },
        38: function (event, callback) {
            console.log(event.keyCode);
            if (callback) {
                callback();
            }
        },
        32: null //just let the space happen
    }
});
0
source

All Articles