From abb5646eb1785c7040c039131c92f6684c71e933 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Sat, 3 Oct 2015 22:11:02 -0500 Subject: [PATCH] Core: Remove tabindex when sort is disabled See http://stackoverflow.com/a/16827628/145346 --- js/jquery.tablesorter.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index b941b5bd..81369e61 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -513,19 +513,27 @@ } function updateHeader(table) { - var index, s, $th, col, + var index, isDisabled, $th, col, c = table.config, len = c.$headers.length; for ( index = 0; index < len; index++ ) { $th = c.$headers.eq( index ); col = ts.getColumnData( table, c.headers, index, true ); // add 'sorter-false' class if 'parser-false' is set - s = ts.getData( $th, col, 'sorter' ) === 'false' || ts.getData( $th, col, 'parser' ) === 'false'; - $th[0].sortDisabled = s; - $th[ s ? 'addClass' : 'removeClass' ]('sorter-false').attr('aria-disabled', '' + s); + isDisabled = ts.getData( $th, col, 'sorter' ) === 'false' || ts.getData( $th, col, 'parser' ) === 'false'; + $th[0].sortDisabled = isDisabled; + $th[ isDisabled ? 'addClass' : 'removeClass' ]( 'sorter-false' ).attr( 'aria-disabled', '' + isDisabled ); + // disable tab index on disabled cells + if ( c.tabIndex ) { + if ( isDisabled ) { + $th.removeAttr( 'tabindex' ); + } else { + $th.attr( 'tabindex', '0' ); + } + } // aria-controls - requires table ID if (table.id) { - if (s) { + if ( isDisabled ) { $th.removeAttr('aria-controls'); } else { $th.attr('aria-controls', table.id);