Skip to content

Commit

Permalink
fix: only create focus button mode div for body cells (#7274)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Mar 26, 2024
1 parent f38b8b3 commit 19e1f16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/grid/src/vaadin-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,6 @@ export const GridMixin = (superClass) =>
});
}

if (column && column._onCellKeyDown) {
cell.addEventListener('keydown', column._onCellKeyDown.bind(column));
}

const slot = document.createElement('slot');
slot.setAttribute('name', slotName);

Expand Down Expand Up @@ -681,6 +677,9 @@ export const GridMixin = (superClass) =>
cell = column._cells.find((cell) => cell._vacant);
if (!cell) {
cell = this._createCell('td', column);
if (column._onCellKeyDown) {
cell.addEventListener('keydown', column._onCellKeyDown.bind(column));
}
column._cells.push(cell);
}
cell.setAttribute('part', 'cell body-cell');
Expand Down Expand Up @@ -724,7 +723,13 @@ export const GridMixin = (superClass) =>
// Header & footer
const tagName = section === 'header' ? 'th' : 'td';
if (isColumnRow || column.localName === 'vaadin-grid-column-group') {
cell = column[`_${section}Cell`] || this._createCell(tagName, column);
cell = column[`_${section}Cell`];
if (!cell) {
cell = this._createCell(tagName);
if (column._onCellKeyDown) {
cell.addEventListener('keydown', column._onCellKeyDown.bind(column));
}
}
cell._column = column;
row.appendChild(cell);
column[`_${section}Cell`] = cell;
Expand Down
9 changes: 9 additions & 0 deletions packages/grid/test/keyboard-navigation-cell-button.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { flushGrid } from './helpers.js';

let grid;

function getHeaderCell(grid, index) {
return grid.$.header.querySelectorAll('[part~="cell"]')[index];
}

function getRowCell(rowIndex, cellIndex) {
return grid.$.items.children[rowIndex].children[cellIndex];
}
Expand Down Expand Up @@ -89,4 +93,9 @@ describe('keyboard navigation - focus button mode', () => {
cell2.focus();
expect(cell.firstChild.getAttribute('part')).to.be.null;
});

it('should not create a focusable div with role="button" inside the header cell', () => {
const headerCell = getHeaderCell(grid, 0);
expect(headerCell.firstChild.localName).to.equal('slot');
});
});

0 comments on commit 19e1f16

Please sign in to comment.