1
- import { html , customElement , property , css , repeat , state } from '@umbraco-cms/backoffice/external/lit' ;
1
+ import { html , customElement , property , css , repeat , state , query } from '@umbraco-cms/backoffice/external/lit' ;
2
2
import { UmbTextStyles } from '@umbraco-cms/backoffice/style' ;
3
3
import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry' ;
4
4
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
5
5
import { UmbPropertyValueChangeEvent } from '@umbraco-cms/backoffice/property-editor' ;
6
+ import { generateAlias } from '@umbraco-cms/backoffice/utils' ;
6
7
7
8
export type UmbCrop = {
8
9
label : string ;
@@ -19,13 +20,18 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement
19
20
extends UmbLitElement
20
21
implements UmbPropertyEditorUiElement
21
22
{
23
+ @query ( '#label' )
24
+ private _labelInput ! : HTMLInputElement ;
25
+
22
26
//TODO MAKE TYPE
23
27
@property ( { attribute : false } )
24
28
value : UmbCrop [ ] = [ ] ;
25
29
26
30
@state ( )
27
31
editCropAlias = '' ;
28
32
33
+ #oldInputValue = '' ;
34
+
29
35
#onRemove( alias : string ) {
30
36
this . value = [ ...this . value . filter ( ( item ) => item . alias !== alias ) ] ;
31
37
this . dispatchEvent ( new UmbPropertyValueChangeEvent ( ) ) ;
@@ -92,6 +98,7 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement
92
98
this . dispatchEvent ( new UmbPropertyValueChangeEvent ( ) ) ;
93
99
94
100
form . reset ( ) ;
101
+ this . _labelInput . focus ( ) ;
95
102
}
96
103
97
104
#renderActions( ) {
@@ -101,6 +108,24 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement
101
108
: html `<uui- butto n look= "secondary" type = "submit" label = "Add" > </ uui- butto n> ` ;
102
109
}
103
110
111
+ #onLabelInput( ) {
112
+ const value = this . _labelInput . value ?? '' ;
113
+
114
+ const aliasValue = generateAlias ( value ) ;
115
+
116
+ const alias = this . shadowRoot ?. querySelector ( '#alias' ) as HTMLInputElement ;
117
+
118
+ if ( ! alias ) return ;
119
+
120
+ const oldAliasValue = generateAlias ( this . #oldInputValue) ;
121
+
122
+ if ( alias . value === oldAliasValue || ! alias . value ) {
123
+ alias . value = aliasValue ;
124
+ }
125
+
126
+ this . #oldInputValue = value ;
127
+ }
128
+
104
129
render ( ) {
105
130
if ( ! this . value ) this . value = [ ] ;
106
131
@@ -109,7 +134,14 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement
109
134
<for m @submit = ${ this . #onSubmit} >
110
135
<div class= "input" >
111
136
<uui- label for = "label" > Label </ uui- label>
112
- <uui- input label= "Label" id = "label" name = "label" type = "text" autocomplete = "false" value = "" > </ uui- input>
137
+ <uui- input
138
+ @input = ${ this . #onLabelInput}
139
+ label= "Label"
140
+ id = "label"
141
+ name= "label"
142
+ type= "text"
143
+ auto complete= "false"
144
+ value= ""> </ uui- input>
113
145
</ div>
114
146
<div class= "input" >
115
147
<uui- label for = "alias" > Alias </ uui- label>
0 commit comments