Skip to content

Commit c01cb20

Browse files
committed
fix: converts the property-editor-ui-textarea to a form mixin
1 parent 3152372 commit c01cb20

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/packages/property-editors/textarea/property-editor-ui-textarea.element.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { css, customElement, html, property, state, styleMap } from '@umbraco-cms/backoffice/external/lit';
1+
import { css, customElement, html, ifDefined, property, state, styleMap } from '@umbraco-cms/backoffice/external/lit';
22
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
33
import { UmbPropertyValueChangeEvent } from '@umbraco-cms/backoffice/property-editor';
44
import type { StyleInfo } from '@umbraco-cms/backoffice/external/lit';
55
import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor';
66
import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry';
7-
import type { UUITextareaElement } from '@umbraco-cms/backoffice/external/uui';
7+
import { UmbFormControlMixin } from '@umbraco-cms/backoffice/validation';
8+
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
89

910
@customElement('umb-property-editor-ui-textarea')
10-
export class UmbPropertyEditorUITextareaElement extends UmbLitElement implements UmbPropertyEditorUiElement {
11-
@property()
12-
value = '';
13-
11+
export class UmbPropertyEditorUITextareaElement
12+
extends UmbFormControlMixin<string>(UmbLitElement, undefined)
13+
implements UmbPropertyEditorUiElement
14+
{
1415
/**
1516
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
1617
* @type {boolean}
@@ -47,8 +48,14 @@ export class UmbPropertyEditorUITextareaElement extends UmbLitElement implements
4748
};
4849
}
4950

50-
#onInput(event: InputEvent & { target: UUITextareaElement }) {
51-
this.value = event.target.value as string;
51+
protected override firstUpdated(): void {
52+
this.addFormControlElement(this.shadowRoot!.querySelector('uui-textarea')!);
53+
}
54+
55+
#onInput(event: InputEvent) {
56+
const newValue = (event.target as HTMLTextAreaElement).value;
57+
if (newValue === this.value) return;
58+
this.value = newValue;
5259
this.dispatchEvent(new UmbPropertyValueChangeEvent());
5360
}
5461

@@ -58,15 +65,16 @@ export class UmbPropertyEditorUITextareaElement extends UmbLitElement implements
5865
label="Textarea"
5966
style=${styleMap(this._css)}
6067
.autoHeight=${this._rows ? false : true}
61-
.maxlength=${this._maxChars}
62-
.rows=${this._rows}
68+
maxlength=${ifDefined(this._maxChars)}
69+
rows=${ifDefined(this._rows)}
6370
.value=${this.value ?? ''}
6471
@input=${this.#onInput}
6572
?readonly=${this.readonly}></uui-textarea>
6673
`;
6774
}
6875

69-
static override styles = [
76+
static styles = [
77+
UmbTextStyles,
7078
css`
7179
uui-textarea {
7280
width: 100%;

0 commit comments

Comments
 (0)