Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore sorter click if event is canceled #5089

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -16,7 +16,7 @@ import {

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

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

Expand All @@ -47,6 +48,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