Skip to content

Commit

Permalink
fix: ensure grid has tabbable elements after it becomes visible (#8102)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Nov 7, 2024
1 parent 4823a40 commit ecb3ecd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/grid/src/vaadin-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,9 @@ export const GridMixin = (superClass) =>
e.stopPropagation();
this.__tryToRecalculateColumnWidthsIfPending();

// Ensure header and footer have tabbable elements
this._resetKeyboardNavigation();

requestAnimationFrame(() => {
this.__scrollToPendingIndexes();
});
Expand Down
17 changes: 14 additions & 3 deletions packages/grid/test/hidden-grid.common.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import { fixtureSync, nextFrame, nextRender, oneEvent } from '@vaadin/testing-helpers';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import { fire, flushGrid, getBodyCellContent, infiniteDataProvider } from './helpers.js';
import { fire, flushGrid, getBodyCellContent, getHeaderCell, infiniteDataProvider } from './helpers.js';

describe('hidden grid', () => {
let grid;

describe('initially hidden', () => {
beforeEach(() => {
beforeEach(async () => {
grid = fixtureSync(`
<vaadin-grid style="height: 200px; width: 200px;" hidden size="1">
<vaadin-grid-column header="foo"></vaadin-grid-column>
</vaadin-grid>
`);
await nextRender();
grid.querySelector('vaadin-grid-column').renderer = (root, _, model) => {
root.textContent = model.index;
};
Expand All @@ -31,6 +33,15 @@ describe('hidden grid', () => {
await nextFrame();
expect(getBodyCellContent(grid, 0, 0).textContent).to.equal('0');
});

it('should make it possible to Tab to header', async () => {
grid.removeAttribute('hidden');
await oneEvent(grid, 'animationend');
await nextFrame();

await sendKeys({ press: 'Tab' });
expect(grid.shadowRoot.activeElement).to.equal(getHeaderCell(grid, 0, 0));
});
});

describe('hiding the grid', () => {
Expand Down

0 comments on commit ecb3ecd

Please sign in to comment.