Skip to content

Commit

Permalink
fix: prevent toggling opened state on click when disabled (#6331) (#6332
Browse files Browse the repository at this point in the history
)
  • Loading branch information
web-padawan authored Aug 9, 2023
1 parent 0a9e65b commit 772499c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/accordion/test/accordion-panel.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
import { click, fixtureSync, nextRender } from '@vaadin/testing-helpers';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import '../vaadin-accordion-panel.js';
Expand Down Expand Up @@ -84,6 +84,12 @@ describe('vaadin-accordion-panel', () => {
expect(panel.opened).to.be.false;
});

it(`should not update opened on ${type} heading button click when disabled`, () => {
panel.disabled = true;
click(toggle);
expect(panel.opened).to.be.false;
});

it(`should toggle opened on ${type} heading button Enter`, async () => {
toggle.focus();

Expand Down
4 changes: 4 additions & 0 deletions packages/details/src/collapsible-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export const CollapsibleMixin = (superClass) =>
// Only handle click and not keydown, because `vaadin-details-summary` uses `ButtonMixin`
// that already covers this logic, and `vaadin-accordion-heading` uses native `<button>`.
this.addEventListener('click', ({ target }) => {
if (this.disabled) {
return;
}

const summary = this.focusElement;

if (summary && (target === summary || summary.contains(target))) {
Expand Down
8 changes: 7 additions & 1 deletion packages/details/test/details.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync } from '@vaadin/testing-helpers';
import { click, fixtureSync } from '@vaadin/testing-helpers';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import '../vaadin-details.js';
Expand Down Expand Up @@ -108,6 +108,12 @@ describe('vaadin-details', () => {
expect(details.opened).to.be.false;
});

it(`should not update opened on ${type} summary click when disabled`, () => {
details.disabled = true;
click(summary);
expect(details.opened).to.be.false;
});

it(`should toggle opened on ${type} summary child click`, () => {
const child = summary.firstChild;
if (child.nodeType === Node.ELEMENT_NODE) {
Expand Down

0 comments on commit 772499c

Please sign in to comment.