Skip to content

Commit 4cf9605

Browse files
committed
Fixed an issue with the keyboard navigation when there are hidden columns
1 parent 26d07de commit 4cf9605

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/BootstrapTable.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,12 +709,22 @@ class BootstrapTable extends Component {
709709
handleNavigateCell = ({ x: offSetX, y: offSetY, lastEditCell }) => {
710710
const { pagination } = this.props;
711711
let { x, y, currPage } = this.state;
712-
x += offSetX;
713-
y += offSetY;
714712

715713
const columns = this.store.getColInfos();
714+
const visibleColumnIndices = Object.keys(columns).map((k, index) => columns[k].hidden ? -1 : index).filter(k => k !== -1);
715+
716+
if (visibleColumnIndices.indexOf(x) === 0 && offSetX < 0) {
717+
x = -1;
718+
} else if ((visibleColumnIndices.indexOf(x) === (visibleColumnIndices.length - 1) && offSetX >= 1)) {
719+
x = Object.keys(columns).length;
720+
} else {
721+
x = visibleColumnIndices[visibleColumnIndices.indexOf(x) + offSetX];
722+
}
723+
y += offSetY;
724+
716725
const visibleRowSize = this.state.data.length;
717726
const visibleColumnSize = Object.keys(columns).filter(k => !columns[k].hidden).length;
727+
const hiddenColumnSize = Object.keys(columns).filter(k => columns[k].hidden).length;
718728

719729
if (y >= visibleRowSize) {
720730
currPage++;
@@ -733,7 +743,7 @@ class BootstrapTable extends Component {
733743
return;
734744
}
735745
y = visibleRowSize - 1;
736-
} else if (x >= visibleColumnSize) {
746+
} else if (x - hiddenColumnSize >= visibleColumnSize) {
737747
if ((y + 1) === visibleRowSize) {
738748
currPage++;
739749
const lastPage = pagination ? this.pagination.getLastPage() : -1;
@@ -746,9 +756,9 @@ class BootstrapTable extends Component {
746756
} else {
747757
y++;
748758
}
749-
x = lastEditCell ? 1 : 0;
759+
x = lastEditCell ? visibleColumnIndices[1] : visibleColumnIndices[0];
750760
} else if (x < 0) {
751-
x = visibleColumnSize - 1;
761+
x = visibleColumnIndices[visibleColumnIndices.length - 1];
752762
if (y === 0) {
753763
currPage--;
754764
if (currPage > 0) {

0 commit comments

Comments
 (0)