Disabling jQuery UI Accordion with space bar toggling

前端 未结 3 1334
情歌与酒
情歌与酒 2020-12-06 19:54

I see in jQuery UI accordian you can use the space bar to toggle active headers. How can one disable this? I don\'t want the user to use keyboard to interact with the accord

3条回答
  •  -上瘾入骨i
    2020-12-06 20:20

    I developed an answer to just enabling the spacebar, but it could be expanded for other keydown events you want to override.

    /*
     * Detect spacebar and return immediately, otherwise call standard behaviour
     * The 'solution' of deleting the event handler caused other errors
     * http://stackoverflow.com/a/7008791
    */
    $.ui.accordion.prototype._originalKeyDown = $.ui.accordion.prototype._keydown;
    $.ui.accordion.prototype._keydown = function( event ) {
        var keyCode = $.ui.keyCode;
    
        if (event.keyCode == keyCode.SPACE) {
            return;
        }
        // call the original method
        this._originalKeyDown(event);
    };
    

提交回复
热议问题