dispatch event when value updates

This commit is contained in:
Mads Rasmussen
2023-01-20 12:56:50 +01:00
parent b953b60b10
commit deb4ac9fec
2 changed files with 10 additions and 4 deletions

View File

@@ -0,0 +1,6 @@
export class UmbPropertyValueChangeEvent extends Event {
public constructor() {
// mimics the native change event
super('property-value-change', { bubbles: true, composed: false, cancelable: false });
}
}

View File

@@ -3,6 +3,7 @@ import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
import { customElement, property, state } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
import { UUIInputElement, UUIInputEvent } from '@umbraco-ui/uui-input';
import { UmbPropertyValueChangeEvent } from '../..';
export type MultipleTextStringConfigData = Array<{
alias: 'minNumber' | 'maxNumber';
@@ -65,16 +66,15 @@ export class UmbPropertyEditorUIMultipleTextStringElement extends LitElement {
private _onAdd() {
this._value = [...this._value, { value: '' }];
this.dispatchEvent(new CustomEvent('property-value-change'));
this.dispatchEvent(new UmbPropertyValueChangeEvent());
}
private _onInput(event: UUIInputEvent) {
const target = event.target as UUIInputElement;
const value = target.value as string;
const valueIndex = Number(target.dataset.valueIndex);
this._value[valueIndex] = { value };
this.dispatchEvent(new CustomEvent('property-value-change'));
this._value = this._value.map((item, index) => (index === valueIndex ? { value } : item));
this.dispatchEvent(new UmbPropertyValueChangeEvent());
}
render() {