1
1
import type { UploadProps as RcUploadProps } from '../vc-upload' ;
2
2
import VcUpload from '../vc-upload' ;
3
3
import UploadList from './UploadList' ;
4
- import type {
5
- UploadType ,
6
- UploadListType ,
7
- UploadFile ,
8
- UploadChangeParam ,
9
- ShowUploadListInterface ,
10
- FileType ,
11
- } from './interface' ;
4
+ import type { UploadFile , UploadChangeParam , ShowUploadListInterface , FileType } from './interface' ;
12
5
import { uploadProps } from './interface' ;
13
6
import { file2Obj , getFileItem , removeFileItem , updateFileList } from './utils' ;
14
7
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver' ;
@@ -25,6 +18,7 @@ import { useInjectFormItemContext } from '../form';
25
18
26
19
// CSSINJS
27
20
import useStyle from './style' ;
21
+ import { useInjectDisabled } from '../config-provider/DisabledContext' ;
28
22
29
23
export const LIST_IGNORE = `__LIST_IGNORE_${ Date . now ( ) } __` ;
30
24
@@ -33,18 +27,25 @@ export default defineComponent({
33
27
name : 'AUpload' ,
34
28
inheritAttrs : false ,
35
29
props : initDefaultProps ( uploadProps ( ) , {
36
- type : 'select' as UploadType ,
30
+ type : 'select' ,
37
31
multiple : false ,
38
32
action : '' ,
39
33
data : { } ,
40
34
accept : '' ,
41
35
showUploadList : true ,
42
- listType : 'text' as UploadListType , // or picture
36
+ listType : 'text' , // or picture
43
37
disabled : false ,
44
38
supportServerRender : true ,
45
39
} ) ,
46
40
setup ( props , { slots, attrs, expose } ) {
47
41
const formItemContext = useInjectFormItemContext ( ) ;
42
+ const { prefixCls, direction, disabled } = useConfigInject ( 'upload' , props ) ;
43
+
44
+ // style
45
+ const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
46
+ const disabledContext = useInjectDisabled ( ) ;
47
+ const mergedDisabled = computed ( ( ) => disabledContext . value ?? disabled . value ) ;
48
+
48
49
const [ mergedFileList , setMergedFileList ] = useMergedState ( props . defaultFileList || [ ] , {
49
50
value : toRef ( props , 'fileList' ) ,
50
51
postState : list => {
@@ -59,7 +60,7 @@ export default defineComponent({
59
60
} ) ;
60
61
const dragState = ref ( 'drop' ) ;
61
62
62
- const upload = ref ( ) ;
63
+ const upload = ref ( null ) ;
63
64
onMounted ( ( ) => {
64
65
devWarning (
65
66
props . fileList !== undefined || attrs . value === undefined ,
@@ -294,11 +295,6 @@ export default defineComponent({
294
295
upload,
295
296
} ) ;
296
297
297
- const { prefixCls, direction } = useConfigInject ( 'upload' , props ) ;
298
-
299
- // style
300
- const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
301
-
302
298
const [ locale ] = useLocaleReceiver (
303
299
'Upload' ,
304
300
defaultLocale . Upload ,
@@ -312,7 +308,6 @@ export default defineComponent({
312
308
previewFile,
313
309
onPreview,
314
310
onDownload,
315
- disabled,
316
311
isImageUrl,
317
312
progress,
318
313
itemRender,
@@ -330,7 +325,7 @@ export default defineComponent({
330
325
onPreview = { onPreview }
331
326
onDownload = { onDownload }
332
327
onRemove = { handleRemove }
333
- showRemoveIcon = { ! disabled && showRemoveIcon }
328
+ showRemoveIcon = { ! mergedDisabled . value && showRemoveIcon }
334
329
showPreviewIcon = { showPreviewIcon }
335
330
showDownloadIcon = { showDownloadIcon }
336
331
removeIcon = { removeIcon }
@@ -350,7 +345,7 @@ export default defineComponent({
350
345
) ;
351
346
} ;
352
347
return ( ) => {
353
- const { listType, disabled , type } = props ;
348
+ const { listType, type } = props ;
354
349
const { class : className , style : styleName , ...transAttrs } = attrs ;
355
350
const rcUploadProps = {
356
351
onBatchStart,
@@ -363,19 +358,20 @@ export default defineComponent({
363
358
prefixCls : prefixCls . value ,
364
359
beforeUpload : mergedBeforeUpload ,
365
360
onChange : undefined ,
361
+ disabled : mergedDisabled . value ,
366
362
} ;
367
363
delete ( rcUploadProps as any ) . remove ;
368
364
369
365
// Remove id to avoid open by label when trigger is hidden
370
366
// !children: https://github.com/ant-design/ant-design/issues/14298
371
367
// disabled: https://github.com/ant-design/ant-design/issues/16478
372
368
// https://github.com/ant-design/ant-design/issues/24197
373
- if ( ! slots . default || disabled ) {
369
+ if ( ! slots . default || mergedDisabled . value ) {
374
370
delete rcUploadProps . id ;
375
371
}
376
372
377
373
const rtlCls = {
378
- [ `${ prefixCls } -rtl` ] : direction . value === 'rtl' ,
374
+ [ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
379
375
} ;
380
376
381
377
if ( type === 'drag' ) {
@@ -387,7 +383,7 @@ export default defineComponent({
387
383
file => file . status === 'uploading' ,
388
384
) ,
389
385
[ `${ prefixCls . value } -drag-hover` ] : dragState . value === 'dragover' ,
390
- [ `${ prefixCls . value } -disabled` ] : disabled ,
386
+ [ `${ prefixCls . value } -disabled` ] : mergedDisabled . value ,
391
387
[ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
392
388
} ,
393
389
attrs . class ,
@@ -423,7 +419,7 @@ export default defineComponent({
423
419
const uploadButtonCls = classNames ( prefixCls . value , {
424
420
[ `${ prefixCls . value } -select` ] : true ,
425
421
[ `${ prefixCls . value } -select-${ listType } ` ] : true ,
426
- [ `${ prefixCls . value } -disabled` ] : disabled ,
422
+ [ `${ prefixCls . value } -disabled` ] : mergedDisabled . value ,
427
423
[ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
428
424
} ) ;
429
425
const children = flattenChildren ( slots . default ?.( ) ) ;
0 commit comments