Skip to content

Commit 7e489d0

Browse files
committed
Fix Accessibility keyboard when sorting with <th>
Fix wenzhixin#1393 Example: http://jsfiddle.net/e3nk137y/3061/
1 parent ebec05f commit 7e489d0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/bootstrap-table.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@
710710
sprintf(' rowspan="%s"', column.rowspan),
711711
sprintf(' colspan="%s"', column.colspan),
712712
sprintf(' data-field="%s"', column.field),
713+
"tabindex='0'",
713714
'>');
714715

715716
html.push(sprintf('<div class="th-inner %s">', that.options.sortable && column.sortable ?
@@ -748,6 +749,15 @@
748749
}
749750
});
750751

752+
this.$container.find("th").off('keypress').on('keypress', function (event) {
753+
if (that.options.sortable && $(this).data().sortable) {
754+
var code = event.keyCode || event.which;
755+
if(code == 13) { //Enter keycode
756+
that.onSort(event);
757+
}
758+
}
759+
});
760+
751761
if (!this.options.showHeader || this.options.cardView) {
752762
this.$header.hide();
753763
this.$tableHeader.hide();
@@ -861,7 +871,7 @@
861871
};
862872

863873
BootstrapTable.prototype.onSort = function (event) {
864-
var $this = $(event.currentTarget).parent(),
874+
var $this = event.type === "keypress" ? $(event.currentTarget) : $(event.currentTarget).parent(),
865875
$this_ = this.$header.find('th').eq($this.index());
866876

867877
this.$header.add(this.$header_).find('span.order').remove();

0 commit comments

Comments
 (0)