Select property-editor: support name/value option data
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { html, customElement, property, state } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { customElement, html, property, state } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
|
||||
import { UmbPropertyValueChangeEvent } from '@umbraco-cms/backoffice/property-editor';
|
||||
import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor';
|
||||
@@ -13,23 +13,29 @@ export class UmbPropertyEditorUISelectElement extends UmbLitElement implements U
|
||||
@property()
|
||||
value?: string = '';
|
||||
|
||||
@state()
|
||||
private _list: Array<Option> = [];
|
||||
|
||||
public set config(config: UmbPropertyEditorConfigCollection | undefined) {
|
||||
if (!config) return;
|
||||
|
||||
const listData = config.getValueByAlias<string[]>('items');
|
||||
this._list = listData?.map((option) => ({ value: option, name: option, selected: option === this.value })) ?? [];
|
||||
const items = config.getValueByAlias('items');
|
||||
|
||||
if (Array.isArray(items) && items.length > 0) {
|
||||
this._options =
|
||||
typeof items[0] === 'string'
|
||||
? items.map((item) => ({ name: item, value: item, selected: item === this.value }))
|
||||
: items.map((item) => ({ name: item.name, value: item.value, selected: item.value === this.value }));
|
||||
}
|
||||
}
|
||||
|
||||
@state()
|
||||
private _options: Array<Option> = [];
|
||||
|
||||
#onChange(event: UUISelectEvent) {
|
||||
this.value = event.target.value as string;
|
||||
this.dispatchEvent(new UmbPropertyValueChangeEvent());
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`<uui-select .options=${this._list} @change=${this.#onChange}></uui-select>`;
|
||||
return html`<uui-select .options=${this._options} @change=${this.#onChange}></uui-select>`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ describe('UmbPropertyEditorUISelectElement', () => {
|
||||
let element: UmbPropertyEditorUISelectElement;
|
||||
|
||||
beforeEach(async () => {
|
||||
element = await fixture(html` <umb-property-editor-ui-select></umb-property-editor-ui-select> `);
|
||||
element = await fixture(html`<umb-property-editor-ui-select></umb-property-editor-ui-select>`);
|
||||
});
|
||||
|
||||
it('is defined with its own instance', () => {
|
||||
|
||||
Reference in New Issue
Block a user