Skip to content

Commit

Permalink
fix: ignore sorter click if event is canceled (#5089)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored and vaadin-bot committed Nov 30, 2022
1 parent 6592594 commit 2204714
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/grid/src/vaadin-grid-sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ class GridSorter extends ThemableMixin(DirMixin(PolymerElement)) {

/** @private */
_onClick(e) {
if (e.defaultPrevented) {
// Something else has already handled the click event, do nothing.
return;
}

const activeElement = this.getRootNode().activeElement;
if (this !== activeElement && this.contains(activeElement)) {
// Some focusable content inside the sorter was clicked, do nothing.
Expand Down
9 changes: 8 additions & 1 deletion packages/grid/test/sorting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {

describe('sorting', () => {
describe('sorter', () => {
let sorter, button, orderIndicator;
let sorter, title, button, orderIndicator;

beforeEach(() => {
sorter = fixtureSync(`
Expand All @@ -27,6 +27,7 @@ describe('sorting', () => {
</vaadin-grid-sorter>
`);
button = sorter.querySelector('button');
title = sorter.querySelector('.title');
orderIndicator = sorter.shadowRoot.querySelector('[part="order"]');
});

Expand All @@ -49,6 +50,12 @@ describe('sorting', () => {
expect(sorter.direction).to.equal(null);
});

it('should not toggle if click event is already consumed', () => {
title.addEventListener('click', (e) => e.preventDefault());
click(title);
expect(sorter.direction).to.equal(null);
});

it('should fire a sorter-changed event', () => {
const spy = sinon.spy();
sorter.addEventListener('sorter-changed', spy);
Expand Down

0 comments on commit 2204714

Please sign in to comment.