Skip to content

Commit 19e1f16

Browse files
authored
fix: only create focus button mode div for body cells (#7274)
1 parent f38b8b3 commit 19e1f16

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

packages/grid/src/vaadin-grid-mixin.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,6 @@ export const GridMixin = (superClass) =>
589589
});
590590
}
591591

592-
if (column && column._onCellKeyDown) {
593-
cell.addEventListener('keydown', column._onCellKeyDown.bind(column));
594-
}
595-
596592
const slot = document.createElement('slot');
597593
slot.setAttribute('name', slotName);
598594

@@ -681,6 +677,9 @@ export const GridMixin = (superClass) =>
681677
cell = column._cells.find((cell) => cell._vacant);
682678
if (!cell) {
683679
cell = this._createCell('td', column);
680+
if (column._onCellKeyDown) {
681+
cell.addEventListener('keydown', column._onCellKeyDown.bind(column));
682+
}
684683
column._cells.push(cell);
685684
}
686685
cell.setAttribute('part', 'cell body-cell');
@@ -724,7 +723,13 @@ export const GridMixin = (superClass) =>
724723
// Header & footer
725724
const tagName = section === 'header' ? 'th' : 'td';
726725
if (isColumnRow || column.localName === 'vaadin-grid-column-group') {
727-
cell = column[`_${section}Cell`] || this._createCell(tagName, column);
726+
cell = column[`_${section}Cell`];
727+
if (!cell) {
728+
cell = this._createCell(tagName);
729+
if (column._onCellKeyDown) {
730+
cell.addEventListener('keydown', column._onCellKeyDown.bind(column));
731+
}
732+
}
728733
cell._column = column;
729734
row.appendChild(cell);
730735
column[`_${section}Cell`] = cell;

packages/grid/test/keyboard-navigation-cell-button.common.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { flushGrid } from './helpers.js';
55

66
let grid;
77

8+
function getHeaderCell(grid, index) {
9+
return grid.$.header.querySelectorAll('[part~="cell"]')[index];
10+
}
11+
812
function getRowCell(rowIndex, cellIndex) {
913
return grid.$.items.children[rowIndex].children[cellIndex];
1014
}
@@ -89,4 +93,9 @@ describe('keyboard navigation - focus button mode', () => {
8993
cell2.focus();
9094
expect(cell.firstChild.getAttribute('part')).to.be.null;
9195
});
96+
97+
it('should not create a focusable div with role="button" inside the header cell', () => {
98+
const headerCell = getHeaderCell(grid, 0);
99+
expect(headerCell.firstChild.localName).to.equal('slot');
100+
});
92101
});

0 commit comments

Comments
 (0)