Skip to content

Commit ff643f6

Browse files
authored
fix: use cell for grid viewport check in focus button mode (#13330)
1 parent a8d4dea commit ff643f6

3 files changed

Lines changed: 65 additions & 29 deletions

File tree

‎packages/grid-pro/test/edit-column.test.js‎

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import { expect } from '@vaadin/chai-plugins';
22
import { sendKeys } from '@vaadin/test-runner-commands';
3-
import {
4-
aTimeout,
5-
enter,
6-
esc,
7-
fixtureSync,
8-
focusin,
9-
focusout,
10-
isFirefox,
11-
nextFrame,
12-
oneEvent,
13-
} from '@vaadin/testing-helpers';
3+
import { aTimeout, enter, esc, fixtureSync, focusin, focusout, nextFrame, oneEvent } from '@vaadin/testing-helpers';
144
import sinon from 'sinon';
155
import '../src/vaadin-grid-pro.js';
166
import '../src/vaadin-grid-pro-edit-column.js';
@@ -666,8 +656,7 @@ describe('edit column', () => {
666656
expect(hasEditablePart(0, cells.length - 1)).to.be.true;
667657
});
668658

669-
// Focus button mode that is active on MacOS causes issues with Tab key navigation in Firefox when run with Playwright
670-
(isFirefox && isMac ? it.skip : it)('should navigate through editable cells with Tab', async () => {
659+
it('should navigate through editable cells with Tab', async () => {
671660
let cell = getCellByColumnPath('col1');
672661
cell.focus();
673662
await sendKeys({ press: 'Enter' });
@@ -686,22 +675,19 @@ describe('edit column', () => {
686675
expect(getCellEditor(cell)).to.be.ok;
687676
});
688677

689-
(isFirefox && isMac ? it.skip : it)(
690-
'should focus next editable cell outside viewport with singleCellEdit',
691-
async () => {
692-
grid.singleCellEdit = true;
678+
it('should focus next editable cell outside viewport with singleCellEdit', async () => {
679+
grid.singleCellEdit = true;
693680

694-
const cell = getCellByColumnPath('col3');
695-
cell.focus();
696-
await sendKeys({ press: 'Enter' });
697-
expect(getCellEditor(cell)).to.be.ok;
681+
const cell = getCellByColumnPath('col3');
682+
cell.focus();
683+
await sendKeys({ press: 'Enter' });
684+
expect(getCellEditor(cell)).to.be.ok;
698685

699-
await sendKeys({ press: 'Tab' });
686+
await sendKeys({ press: 'Tab' });
700687

701-
const nextCell = getCellByColumnPath('col5');
702-
expect(nextCell.contains(grid.shadowRoot.activeElement)).to.be.true;
703-
},
704-
);
688+
const nextCell = getCellByColumnPath('col5');
689+
expect(nextCell.contains(grid.shadowRoot.activeElement)).to.be.true;
690+
});
705691

706692
it('should edit cell again after it was temporarily removed due to scrolling', async () => {
707693
const cell = getCellByColumnPath('col1');

‎packages/grid/src/vaadin-grid-keyboard-navigation-mixin.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,16 +669,19 @@ export const KeyboardNavigationMixin = (superClass) =>
669669

670670
let focusStepTarget = tabOrder[index];
671671

672+
// In focus button mode, the focusable is a button inside the cell
673+
const focusStepCell = isCell(focusStepTarget?.parentElement) ? focusStepTarget.parentElement : focusStepTarget;
674+
672675
// If the target focusable is tied to a column that is not visible,
673676
// find the first visible column and update the target in order to
674677
// prevent scrolling to the start of the row.
675-
if (focusStepTarget && !this.__isHorizontallyInViewport(focusStepTarget)) {
678+
if (focusStepTarget && !this.__isHorizontallyInViewport(focusStepCell)) {
676679
const firstVisibleColumn = this._getColumnsInOrder().find((column) => this.__isColumnInViewport(column));
677680
if (firstVisibleColumn) {
678681
if (focusStepTarget === this._headerFocusable) {
679682
focusStepTarget = firstVisibleColumn._headerCell;
680683
} else if (focusStepTarget === this._itemsFocusable) {
681-
const row = focusStepTarget.parentElement;
684+
const row = focusStepCell.parentElement;
682685
focusStepTarget = [...row.children].find((cell) => cell._column === firstVisibleColumn);
683686
} else if (focusStepTarget === this._footerFocusable) {
684687
focusStepTarget = firstVisibleColumn._footerCell;

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from '@vaadin/chai-plugins';
2-
import { arrowLeft, arrowRight, aTimeout, fixtureSync } from '@vaadin/testing-helpers';
2+
import { sendKeys } from '@vaadin/test-runner-commands';
3+
import { arrowLeft, arrowRight, aTimeout, fixtureSync, nextFrame } from '@vaadin/testing-helpers';
34
import sinon from 'sinon';
45
import './grid-test-styles.js';
56
import '../src/vaadin-grid.js';
@@ -101,3 +102,49 @@ describe('keyboard navigation - focus button mode', () => {
101102
expect(headerCell.firstElementChild.localName).to.equal('slot');
102103
});
103104
});
105+
106+
describe('keyboard navigation - focus button mode - horizontal scroll', () => {
107+
let lastGlobalFocusable;
108+
109+
beforeEach(async () => {
110+
const wrapper = fixtureSync(`
111+
<div>
112+
<vaadin-grid style="width: 200px"></vaadin-grid>
113+
<input id="last-global-focusable" />
114+
</div>
115+
`);
116+
[grid, lastGlobalFocusable] = wrapper.children;
117+
118+
['a', 'b', 'c', 'd'].forEach((path) => {
119+
const column = document.createElement('vaadin-grid-column');
120+
column.path = path;
121+
column.width = '100px';
122+
column.flexGrow = 0;
123+
column._focusButtonMode = true;
124+
grid.appendChild(column);
125+
});
126+
127+
grid.items = [{ a: 'a', b: 'b', c: 'c', d: 'd' }];
128+
flushGrid(grid);
129+
await nextFrame();
130+
131+
// Scroll so that the third column is the first visible one
132+
grid.$.table.scrollLeft = 250;
133+
await nextFrame();
134+
});
135+
136+
it('should focus the first visible body cell on Shift+Tab when the focusable cell is scrolled out', async () => {
137+
lastGlobalFocusable.focus();
138+
await sendKeys({ press: 'Shift+Tab' });
139+
140+
expect(grid.shadowRoot.activeElement).to.equal(getRowCell(0, 2)._focusButton);
141+
});
142+
143+
it('should focus the focusable body cell on Shift+Tab when it is inside the viewport', async () => {
144+
getRowCell(0, 3).focus();
145+
lastGlobalFocusable.focus();
146+
await sendKeys({ press: 'Shift+Tab' });
147+
148+
expect(grid.shadowRoot.activeElement).to.equal(getRowCell(0, 3)._focusButton);
149+
});
150+
});

0 commit comments

Comments
 (0)