@@ -27,13 +27,17 @@ import { stringOrStringArrayContains } from '@umbraco-cms/backoffice/utils';
27
27
export class UmbInputUploadFieldElement extends UmbLitElement {
28
28
@property ( { type : Object } )
29
29
set value ( value : MediaValueType ) {
30
- if ( ! value ?. src ) return ;
31
- this . src = value . src ;
30
+ this . #src = value ?. src ?? '' ;
32
31
}
33
32
get value ( ) : MediaValueType {
34
- return ! this . temporaryFile ? { src : this . _src } : { temporaryFileId : this . temporaryFile . temporaryUnique } ;
33
+ return {
34
+ src : this . #src,
35
+ temporaryFileId : this . temporaryFile ?. temporaryUnique ,
36
+ } ;
35
37
}
36
38
39
+ #src = '' ;
40
+
37
41
/**
38
42
* @description Allowed file extensions. Allow all if empty.
39
43
* @type {Array<string> }
@@ -50,17 +54,6 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
50
54
@state ( )
51
55
public temporaryFile ?: UmbTemporaryFileModel ;
52
56
53
- public set src ( src : string ) {
54
- this . _src = src ;
55
- this . _previewAlias = this . #getPreviewElementAlias( ) ;
56
- }
57
- public get src ( ) {
58
- return this . _src ;
59
- }
60
-
61
- @state ( )
62
- private _src = '' ;
63
-
64
57
@state ( )
65
58
private _extensions ?: string [ ] ;
66
59
@@ -162,7 +155,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
162
155
163
156
const reader = new FileReader ( ) ;
164
157
reader . onload = ( ) => {
165
- this . src = reader . result as string ;
158
+ this . value = { src : reader . result as string } ;
166
159
} ;
167
160
reader . readAsDataURL ( item . file ) ;
168
161
@@ -180,8 +173,8 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
180
173
}
181
174
182
175
override render ( ) {
183
- if ( this . src && this . _previewAlias ) {
184
- return this . #renderFile( this . src , this . _previewAlias , this . temporaryFile ?. file ) ;
176
+ if ( this . value . src && this . _previewAlias ) {
177
+ return this . #renderFile( this . value . src , this . _previewAlias , this . temporaryFile ?. file ) ;
185
178
} else {
186
179
return this . #renderDropzone( ) ;
187
180
}
@@ -200,7 +193,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
200
193
` ;
201
194
}
202
195
203
- #renderFile( src : string , previewAlias ? : string , file ?: File ) {
196
+ #renderFile( src : string , previewAlias : string , file ?: File ) {
204
197
if ( ! previewAlias ) return 'An error occurred. No previewer found for the file type.' ;
205
198
return html `
206
199
<div id= "wrapper" >
@@ -226,7 +219,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
226
219
}
227
220
228
221
#handleRemove( ) {
229
- this . src = '' ;
222
+ this . value = { src : undefined } ;
230
223
this . temporaryFile = undefined ;
231
224
this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
232
225
}
0 commit comments