diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/member-picker/property-editor-ui-member-picker.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/member-picker/property-editor-ui-member-picker.element.ts index 00d68012c8..8e47ba21b4 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/member-picker/property-editor-ui-member-picker.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/member-picker/property-editor-ui-member-picker.element.ts @@ -1,8 +1,9 @@ -import type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit'; import { html, customElement, property, state } from '@umbraco-cms/backoffice/external/lit'; -import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; +import { UmbPropertyValueChangeEvent } from '@umbraco-cms/backoffice/property-editor'; +import type { NumberRangeValueType } from '@umbraco-cms/backoffice/models'; import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor'; +import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry'; import type { UmbInputMemberElement } from '@umbraco-cms/backoffice/member'; /** @@ -10,58 +11,35 @@ import type { UmbInputMemberElement } from '@umbraco-cms/backoffice/member'; */ @customElement('umb-property-editor-ui-member-picker') export class UmbPropertyEditorUIMemberPickerElement extends UmbLitElement implements UmbPropertyEditorUiElement { - // private _value: Array = []; - - // @property({ type: Array }) - // public set value(value: Array) { - // this._value = Array.isArray(value) ? value : value ? [value] : []; - // } - // public get value(): Array { - // return this._value; - // } - - @property({ type: String }) - public value: string = ''; + @property() + public value?: string; public set config(config: UmbPropertyEditorConfigCollection | undefined) { - const validationLimit = config?.find((x) => x.alias === 'validationLimit'); + if (!config) return; - this._limitMin = (validationLimit?.value as any)?.min; - this._limitMax = (validationLimit?.value as any)?.max; + const minMax = config?.getValueByAlias('validationLimit'); + this.min = minMax?.min ?? 0; + this.max = minMax?.max ?? Infinity; } @state() - _items: Array = []; + min = 0; @state() - private _limitMin?: number; - @state() - private _limitMax?: number; + max = Infinity; - protected updated(_changedProperties: PropertyValueMap | Map): void { - super.updated(_changedProperties); - if (_changedProperties.has('value')) { - this._items = this.value ? this.value.split(',') : []; - } - } - - private _onChange(event: CustomEvent) { - //TODO: This is a hack, something changed so now we need to convert the array to a comma separated string to make it work with the server. - const toCommaSeparatedString = (event.target as UmbInputMemberElement).selection.join(','); - // this.value = (event.target as UmbInputMemberElement).selection; - this.value = toCommaSeparatedString; - this.dispatchEvent(new CustomEvent('property-value-change')); + #onChange(event: CustomEvent & { target: UmbInputMemberElement }) { + this.value = event.target.value; + this.dispatchEvent(new UmbPropertyValueChangeEvent()); } render() { return html` Add + .min=${this.min} + .max=${this.max} + .value=${this.value ?? ''} + @change=${this.#onChange}> `; } }