Skip to content

Commit d7f7bce

Browse files
committed
fix: Display array items with "Array of:" in unions
1 parent 227e582 commit d7f7bce

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

src/ApiTypeDocument.js

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -765,34 +765,46 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
765765
* @private
766766
*/
767767
_multiTypeTemplate({ label, items, typeName, selected, selectTypeCallback, type }) {
768+
const selectedUnion = items[selected];
769+
const unionsSelector = html`<div class="union-type-selector">
770+
<span>${label}:</span>
771+
${items.map(
772+
(item, index) => html`<anypoint-button
773+
class="${typeName}-toggle"
774+
data-index="${index}"
775+
?activated="${selected === index}"
776+
aria-pressed="${selected === index ? 'true' : 'false'}"
777+
@click="${selectTypeCallback}"
778+
?compatibility="${this.compatibility}"
779+
title="Select ${item.label} type"
780+
>${item.label}</anypoint-button
781+
>`
782+
)}
783+
</div>`
784+
const document = html`<api-type-document
785+
class="${typeName}-document"
786+
.amf="${this.amf}"
787+
.parentTypeName="${this.parentTypeName}"
788+
.type="${type}"
789+
?narrow="${this.narrow}"
790+
?noExamplesActions="${this.noExamplesActions}"
791+
?noMainExample="${this._renderMainExample}"
792+
?compatibility="${this.compatibility}"
793+
.mediaType="${this.mediaType}"
794+
?graph="${this.graph}"
795+
></api-type-document>`
796+
if (selectedUnion.isArray) {
797+
return html`
798+
${unionsSelector}
799+
<span>Array of:</span>
800+
<div class="array-children">
801+
${document}
802+
</div>
803+
`;
804+
}
768805
return html`
769-
<div class="union-type-selector">
770-
<span>${label}:</span>
771-
${items.map(
772-
(item, index) => html`<anypoint-button
773-
class="${typeName}-toggle"
774-
data-index="${index}"
775-
?activated="${selected === index}"
776-
aria-pressed="${selected === index ? 'true' : 'false'}"
777-
@click="${selectTypeCallback}"
778-
?compatibility="${this.compatibility}"
779-
title="Select ${item.label} type"
780-
>${item.label}</anypoint-button
781-
>`
782-
)}
783-
</div>
784-
<api-type-document
785-
class="${typeName}-document"
786-
.amf="${this.amf}"
787-
.parentTypeName="${this.parentTypeName}"
788-
.type="${type}"
789-
?narrow="${this.narrow}"
790-
?noExamplesActions="${this.noExamplesActions}"
791-
?noMainExample="${this._renderMainExample}"
792-
?compatibility="${this.compatibility}"
793-
.mediaType="${this.mediaType}"
794-
?graph="${this.graph}"
795-
></api-type-document>
806+
${unionsSelector}
807+
${document}
796808
`;
797809
}
798810

0 commit comments

Comments
 (0)