Skip to content

Commit 69c4b2d

Browse files
author
Nii Yeboah
authored
feat: add cell-focus event to grid (#176)
1 parent 742b2ee commit 69c4b2d

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ export const KeyboardNavigationMixin = (superClass) =>
504504
}
505505
// Inform cell content of the focus (used in <vaadin-grid-sorter>)
506506
cell._content.dispatchEvent(new CustomEvent('cell-focusin', { bubbles: false }));
507+
508+
// Fire a public event for cell focus.
509+
cell.dispatchEvent(new CustomEvent('cell-focus', { bubbles: true, composed: true }));
507510
}
508511

509512
this._detectFocusedItemIndex(e);

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,36 @@ describe('keyboard navigation', () => {
18271827

18281828
expect(spy.callCount).to.equal(1);
18291829
});
1830+
1831+
it('should dispatch cell-focus on keyboard navigation', (done) => {
1832+
const expectedContext = {
1833+
column: grid.querySelector('vaadin-grid-column'),
1834+
detailsOpened: false,
1835+
expanded: false,
1836+
index: 0,
1837+
item: 'foo',
1838+
level: 0,
1839+
section: 'body',
1840+
selected: false
1841+
};
1842+
1843+
tabToBody();
1844+
right();
1845+
1846+
const spy = sinon.spy();
1847+
1848+
grid.addEventListener('cell-focus', (e) => {
1849+
spy();
1850+
1851+
const context = e.target.getEventContext(e);
1852+
expect(context).to.deep.equal(expectedContext);
1853+
done();
1854+
});
1855+
1856+
left();
1857+
1858+
expect(spy.calledOnce).to.be.true;
1859+
});
18301860
});
18311861
});
18321862

0 commit comments

Comments
 (0)