Skip to content

Commit 84ac0b4

Browse files
authored
Merge pull request #1334 from umbraco/bugfix/property-editor-ui-value-can-be-undefined-fix
fix value of property editors can be undefined
2 parents b9103d5 + 3edeae2 commit 84ac0b4

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/packages/core/property-editor/uis/collection-view/config/layout-configuration/property-editor-ui-collection-view-layout-configuration.element.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class UmbPropertyEditorUICollectionViewLayoutConfigurationElement
2626
implements UmbPropertyEditorUiElement
2727
{
2828
@property({ type: Array })
29-
value: Array<LayoutConfig> = [];
29+
value?: Array<LayoutConfig>;
3030

3131
@property({ type: Object, attribute: false })
3232
public config?: UmbPropertyEditorConfigCollection;
@@ -41,64 +41,66 @@ export class UmbPropertyEditorUICollectionViewLayoutConfigurationElement
4141
}
4242

4343
#onAdd() {
44-
this.value = [...this.value, { isSystem: false, icon: 'icon-stop', selected: true }];
44+
this.value = [...(this.value ?? []), { isSystem: false, icon: 'icon-stop', selected: true }];
4545
this.dispatchEvent(new UmbPropertyValueChangeEvent());
4646
}
4747

4848
#onRemove(unique: number) {
49-
const values = [...this.value];
49+
const values = [...(this.value ?? [])];
5050
values.splice(unique, 1);
5151
this.value = values;
5252
this.dispatchEvent(new UmbPropertyValueChangeEvent());
5353
}
5454

5555
#onChangePath(e: UUIInputEvent, index: number) {
56-
const values = [...this.value];
56+
const values = [...(this.value ?? [])];
5757
values[index] = { ...values[index], path: e.target.value as string };
5858
this.value = values;
5959
this.dispatchEvent(new UmbPropertyValueChangeEvent());
6060
}
6161

6262
#onChangeName(e: UUIInputEvent, index: number) {
63-
const values = [...this.value];
63+
const values = [...(this.value ?? [])];
6464
values[index] = { ...values[index], name: e.target.value as string };
6565
this.value = values;
6666
this.dispatchEvent(new UmbPropertyValueChangeEvent());
6767
}
6868

6969
#onChangeSelected(e: UUIBooleanInputEvent, index: number) {
70-
const values = [...this.value];
70+
const values = [...(this.value ?? [])];
7171
values[index] = { ...values[index], selected: e.target.checked };
7272
this.value = values;
7373
this.dispatchEvent(new UmbPropertyValueChangeEvent());
7474
}
7575

7676
async #onIconChange(index: number) {
77-
const icon = this.#iconReader(this.value[index].icon ?? '');
77+
const icon = this.#iconReader((this.value ? this.value[index].icon : undefined) ?? '');
7878

7979
// TODO: send icon data to modal
8080
const modalContext = this._modalContext?.open(UMB_ICON_PICKER_MODAL);
8181
const picked = await modalContext?.onSubmit();
8282
if (!picked) return;
8383

84-
const values = [...this.value];
84+
const values = [...(this.value ?? [])];
8585
values[index] = { ...values[index], icon: `${picked.icon} color-${picked.color}` };
8686
this.value = values;
8787
this.dispatchEvent(new UmbPropertyValueChangeEvent());
8888
}
8989

9090
render() {
9191
return html`<div id="layout-wrapper">
92-
${repeat(
93-
this.value,
94-
(layout, index) => '' + layout.name + layout.icon,
95-
(layout, index) =>
96-
html` <div class="layout-item">
97-
<uui-icon name="icon-navigation"></uui-icon> ${layout.isSystem
98-
? this.renderSystemFieldRow(layout, index)
99-
: this.renderCustomFieldRow(layout, index)}
100-
</div>`,
101-
)}
92+
${this.value
93+
? repeat(
94+
this.value,
95+
(layout, index) => '' + layout.name + layout.icon,
96+
(layout, index) =>
97+
html` <div class="layout-item">
98+
<uui-icon name="icon-navigation"></uui-icon> ${layout.isSystem
99+
? this.renderSystemFieldRow(layout, index)
100+
: this.renderCustomFieldRow(layout, index)}
101+
</div>`,
102+
)
103+
: ''}
102104
</div>
103105
<uui-button
104106
id="add"

0 commit comments

Comments
 (0)