Skip to content

Commit 89cc48d

Browse files
committed
fix(accordion): work around baseclass
1 parent b819948 commit 89cc48d

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

elements/pf-accordion/BaseAccordion.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ export abstract class BaseAccordion extends LitElement {
119119
headers.forEach((header, index) => {
120120
if (header.expanded) {
121121
this.#expandHeader(header, index);
122+
const panel = this.#panelForHeader(header);
123+
if (panel) {
124+
this.#expandPanel(panel);
125+
}
122126
}
123127
});
124128
}

elements/pf-accordion/pf-accordion.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ export class PfAccordion extends BaseAccordion {
4444

4545
@property({ type: Boolean, reflect: true }) fixed = false;
4646

47+
async firstUpdated() {
48+
let index: number | null = null;
49+
if (this.single) {
50+
const allHeaders = [...this.querySelectorAll('pf-accordion-header')];
51+
const lastExpanded = allHeaders.filter(x => x.hasAttribute('expanded')).pop();
52+
if (lastExpanded) {
53+
index = allHeaders.indexOf(lastExpanded);
54+
}
55+
}
56+
await super.firstUpdated();
57+
if (index !== null) {
58+
this.headers.forEach((_, i) => {
59+
this.headers.at(i)?.toggleAttribute('expanded', i === index);
60+
this.panels.at(i)?.toggleAttribute('expanded', i === index);
61+
});
62+
}
63+
}
64+
4765
override async expand(index: number, parentAccordion?: BaseAccordion) {
4866
if (index === -1) {
4967
return;

elements/pf-accordion/test/pf-accordion.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ describe('<pf-accordion>', function() {
954954
[header, secondHeader] = headers;
955955
[panel, secondPanel] = panels;
956956
await allUpdates(element);
957-
await nextFrame();
957+
await aTimeout(100);
958958
});
959959
it('hides the first panel', function() {
960960
expect(panel).to.not.have.attribute('expanded');
@@ -966,6 +966,7 @@ describe('<pf-accordion>', function() {
966966
expect(panels[2]).to.not.have.attribute('expanded');
967967
});
968968
});
969+
969970
describe('with no h* tag in heading lightdom', function() {
970971
beforeEach(async function() {
971972
element = await createFixture<PfAccordion>(html`
@@ -1088,4 +1089,3 @@ describe('<pf-accordion>', function() {
10881089
});
10891090
});
10901091
});
1091-

0 commit comments

Comments
 (0)