Skip to content

Commit b6a22aa

Browse files
sissbrueckervursen
andauthored
fix: cell-focus on click from within shadow DOM (#3714)
* fix: cell-focus on click from within shadow DOM * Apply suggestions from code review Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com> Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
1 parent 8c9e64e commit b6a22aa

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ class Grid extends ElementMixin(
669669
// If focus is on element within the cell content — respect it, do not change
670670
const contentContainsFocusedElement = cellContent.contains(this.getRootNode().activeElement);
671671
// Only focus if mouse is released on cell content itself
672-
const mouseUpWithinCell = cellContent.contains(event.target);
672+
const mouseUpWithinCell = event.composedPath().includes(cellContent);
673673
if (!contentContainsFocusedElement && mouseUpWithinCell) {
674674
cell.focus();
675675
}

‎packages/grid/test/keyboard-navigation.test.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,23 @@ describe('keyboard navigation', () => {
19201920
expect(spy.calledOnce).to.be.true;
19211921
});
19221922

1923+
it('should dispatch cell-focus on mouse up on cell content when grid is in shadow DOM', () => {
1924+
const spy = sinon.spy();
1925+
grid.addEventListener('cell-focus', spy);
1926+
1927+
// Move grid into a shadow DOM
1928+
const container = document.createElement('div');
1929+
document.body.appendChild(container);
1930+
container.attachShadow({ mode: 'open' });
1931+
container.shadowRoot.appendChild(grid);
1932+
1933+
// Mouse down and release on cell content element
1934+
const cell = getRowFirstCell(0);
1935+
mouseDown(cell._content);
1936+
mouseUp(cell._content);
1937+
expect(spy.calledOnce).to.be.true;
1938+
});
1939+
19231940
it('should dispatch cell-focus on mouse up within cell content', () => {
19241941
const spy = sinon.spy();
19251942
grid.addEventListener('cell-focus', spy);

0 commit comments

Comments
 (0)