Skip to content

Commit

Permalink
Merge pull request #1088 from Esri/handle-delayed-init
Browse files Browse the repository at this point in the history
Changed initialization of types to support changes in accordion values
  • Loading branch information
MikeTschudi authored Jan 9, 2025
2 parents 48c611c + 267b33f commit 0be077e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
37 changes: 13 additions & 24 deletions src/components/solution-item-accordion/solution-item-accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ export class SolutionItemAccordion {
"Group"
];

/**
* string[]: Array of template types.
* This array is used during render to ensure only one Accordion item is added for each type.
*/
protected _types: string[] = [];

//--------------------------------------------------------------------------
//
// Watch handlers
Expand All @@ -134,7 +128,6 @@ export class SolutionItemAccordion {

@Watch("templateInfos")
async templateInfosWatchHandler(): Promise<void> {
this._types = [];
this._sortedTemplateInfos = this._sortTemplates();
}

Expand All @@ -160,18 +153,10 @@ export class SolutionItemAccordion {
* StencilJS: Called once just after the component is first connected to the DOM.
*/
async componentWillLoad(): Promise<void> {
this._sortedTemplateInfos = this._sortTemplates();
await this._getTranslations();
}

/**
* StencilJS: Called before each render
*/
async componentWillRender(): Promise<void> {
if (this._sortedTemplateInfos.length === 0 && this.templateInfos?.length > 0) {
this._sortedTemplateInfos = this._sortTemplates();
}
}

/**
* Renders the component.
*/
Expand All @@ -197,17 +182,21 @@ export class SolutionItemAccordion {
* @protected
*/
protected _getAccordion(): VNode {
const types: string[] = [];
const accordion = this._sortedTemplateInfos.reduce((prev, cur) => {
const displayType = this._getTypeForDisplay(cur.type, cur.typeKeywords)

if (types.indexOf(displayType) < 0) {
types.push(displayType);
prev.push(this._getAccordionItem(cur));
}
return prev;
}, []);

return (
<calcite-accordion selectionMode="single">
{
this._sortedTemplateInfos.reduce((prev, cur) => {
const displayType = this._getTypeForDisplay(cur.type, cur.typeKeywords)
if (this._types.indexOf(displayType) < 0) {
this._types.push(displayType);
prev.push(this._getAccordionItem(cur));
}
return prev;
}, [])
accordion
}
</calcite-accordion>
);
Expand Down
3 changes: 1 addition & 2 deletions src/demos/solution-item-accordion.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>Solution Item Accordion</title>
<!--
| Copyright 2024 Esri
Expand Down

0 comments on commit 0be077e

Please sign in to comment.