Skip to content

Commit

Permalink
fix: only create focus button mode div for body cells (#7274) (#7276)
Browse files Browse the repository at this point in the history
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
  • Loading branch information
vaadin-bot and web-padawan committed Mar 26, 2024
1 parent 4e8f960 commit 573389b
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 @@ -574,10 +574,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 @@ -666,6 +662,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 @@ -709,7 +708,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 573389b

Please sign in to comment.