add focus to new element

This commit is contained in:
Mads Rasmussen
2023-01-20 13:02:20 +01:00
parent deb4ac9fec
commit eb0e7b72c7

View File

@@ -67,6 +67,7 @@ export class UmbPropertyEditorUIMultipleTextStringElement extends LitElement {
private _onAdd() {
this._value = [...this._value, { value: '' }];
this.dispatchEvent(new UmbPropertyValueChangeEvent());
this._focusNewItem();
}
private _onInput(event: UUIInputEvent) {
@@ -77,6 +78,13 @@ export class UmbPropertyEditorUIMultipleTextStringElement extends LitElement {
this.dispatchEvent(new UmbPropertyValueChangeEvent());
}
private async _focusNewItem() {
await this.updateComplete;
const inputs = this.shadowRoot?.querySelectorAll('uui-input') as NodeListOf<UUIInputElement>;
const lastInput = inputs[inputs.length - 1];
lastInput.focus();
}
render() {
return html`
${this._renderItems()}