Skip to content

Commit

Permalink
Cherrypick cell focus event (#2196)
Browse files Browse the repository at this point in the history
Co-authored-by: Sascha Ißbrücker <[email protected]>
  • Loading branch information
roastedcpu and sissbruecker authored Oct 28, 2021
1 parent 5cc0233 commit efc8fdf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/vaadin-grid-keyboard-navigation-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@
}
// Inform cell content of the focus (used in <vaadin-grid-sorter>)
cell._content.dispatchEvent(new CustomEvent('cell-focusin', {bubbles: false}));

// Fire a public event for cell focus.
const context = this.getEventContext(e);
cell.dispatchEvent(
new CustomEvent('cell-focus', {bubbles: true, composed: true, detail: {context: context}})
);
}

this._detectFocusedItemIndex(e);
Expand Down Expand Up @@ -743,5 +749,13 @@
}
return null;
}

/**
* Fired when a cell is focused with click or keyboard navigation.
*
* Use context property of @see {@link GridCellFocusEvent} to get detail information about the event.
*
* @event cell-focus
*/
};
</script>
29 changes: 29 additions & 0 deletions test/keyboard-navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,35 @@

expect(spy.callCount).to.equal(1);
});

it('should dispatch cell-focus on keyboard navigation', (done) => {
const expectedContext = {
column: grid.querySelector('vaadin-grid-column'),
detailsOpened: false,
expanded: false,
index: 0,
item: 'foo',
level: 0,
section: 'body',
selected: false
};

tabToBody();
right();

const spy = sinon.spy();

grid.addEventListener('cell-focus', (e) => {
spy();
const context = e.target.getEventContext(e);
expect(context).to.deep.equal(expectedContext);
done();
});

left();

expect(spy.calledOnce).to.be.true;
});
});
});

Expand Down

0 comments on commit efc8fdf

Please sign in to comment.