fix(lion-accordion): make a copy when changing expanded (#2047)

This commit is contained in:
Sciurus7 2023-09-11 14:55:30 +02:00 committed by GitHub
parent 857d47a933
commit cecf5ed573
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': patch
---
lion-accordion now replaces expanded with a copy when it changes on click of an invoker button.

View file

@ -441,7 +441,7 @@ export class LionAccordion extends LitElement {
* @private
*/
__toggleExpanded(value) {
const { expanded } = this;
const expanded = [...this.expanded];
const index = expanded.indexOf(value);
if (index === -1) {

View file

@ -80,6 +80,14 @@ describe('<lion-accordion>', () => {
).to.equal('invoker 1');
});
it('updates expanded with a new array when an invoker is clicked', async () => {
const el = /** @type {LionAccordion} */ (await fixture(basicAccordion));
const invokers = getInvokers(el);
const oldExpanded = el.expanded;
invokers[1].firstElementChild?.dispatchEvent(new Event('click'));
expect(el.expanded).to.not.equal(oldExpanded);
});
it('has [expanded] on current expanded invoker which serves as styling hook', async () => {
const el = /** @type {LionAccordion} */ (await fixture(basicAccordion));
const invokers = getInvokers(el);