生态产品多个设计器现已发布候选版本

查看生态总览
Skip to content

FileUpload ​

Data entry component. This page is the API reference, generated from the source code. Usage guidance and live examples are on the Chinese page.

Anatomy ​

Parts in bold are required.

data-scope="file-upload": root · label · dropzone · trigger · hidden-input · list · item · item-name · item-link · item-size-text · item-preview · item-progress · item-delete-trigger · clear-trigger

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-file-upload>
Vue componentsXhFileUploadClearTrigger XhFileUploadDropzone XhFileUploadHiddenInput XhFileUploadItem XhFileUploadItemDeleteTrigger XhFileUploadItemLink XhFileUploadItemName XhFileUploadItemPreview XhFileUploadItemProgress XhFileUploadItemSizeText XhFileUploadLabel XhFileUploadList XhFileUploadRoot XhFileUploadTrigger
ComposableuseFileUpload
State machinefileUploadMachine
Skin@xihan-ui/styles/file-upload.css

Props ​

PropTypeRequired
labelledboolean
ariaLabelstring
acceptstring | string[]
maxFilesnumber
maxFileSizenumber
minFileSizenumber
disabledboolean
invalidboolean
readOnlyboolean
requiredboolean
namestring
filesFile[]
defaultFilesFile[]
allowDropboolean
allowPasteboolean
validate(file: File, context: FileUploadValidateContext) => string | string[] | null | undefined
maxConcurrentUploadsnumber
directoryboolean
capture'user' | 'environment'
linkTargetstring
remoteFilesFileUploadRemoteFile[]
defaultRemoteFilesFileUploadRemoteFile[]
upload(request: FileUploadRequest) => Promise<FileUploadResult | undefined | void> | FileUploadResult | undefined | void
autoUploadboolean
translationsPartial<FileUploadTranslations>
onFilesChange(details: FileUploadFilesChangeDetails) => void
onClear() => void
onFileAccept(details: FileUploadFileAcceptDetails) => void
onFileReject(details: FileUploadFileRejectDetails) => void
onRemoteFilesChange(details: FileUploadRemoteFilesChangeDetails) => void
onUploadComplete(details: FileUploadCompleteDetails) => void
onUploadError(details: FileUploadErrorDetails) => void
onUploadCancel(details: FileUploadCancelDetails) => void

FileUploadRemoteFile ​

Elements of remoteFiles.

FieldTypeRequired
idstringYes
namestringYes
sizenumber
typestring
urlstring

Events ​

Custom elements put the payload in detail; Vue emits an event of the same name.

EventPayload
files-changeFileUploadFilesChangeDetails
clear``
remote-files-changeFileUploadRemoteFilesChangeDetails
upload-completeFileUploadCompleteDetails
upload-errorFileUploadErrorDetails
upload-cancelFileUploadCancelDetails
file-acceptFileUploadFileAcceptDetails
file-rejectFileUploadFileRejectDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhFileUploadRootdefaultFileUploadRootSlotProps
XhFileUploadRootlabel—
XhFileUploadRootdropzone—

React adapter props ​

Only the props each component declares itself: DOM attributes inherited from ComponentPropsWithRef are left out, and root props already listed in the Props table are not repeated. The Vue counterpart is the slot table above.

React componentPropTypeRequired
XhFileUploadItemfileFileUploadFile
XhFileUploadItemindexnumber | string
XhFileUploadRootlabelReactNode
XhFileUploadRootdropzoneReactNode
XhFileUploadRootclearableboolean
XhFileUploadRootchildrenSlotChildren<FileUploadRootSlotProps>

State ​

Public state is written to data-state.

PartValues
itemuploadOf(file)?.status
item-progressupload?.status

The following names are internal to the state machine.

States: idle · dragging

Events: FILES.SET · FILES.ADD · FILE.DELETE · FILES.CLEAR · PICKER.OPEN · DRAG.OVER · DRAG.LEAVE · DROP · PASTE · UPLOAD.CANCEL · UPLOAD.START · REMOTE.DELETE · FORM.RESET · PRESS.START · PRESS.END · LIST.TRACKED · PROGRESS.SETTLED

Guards: canChange · canTransfer · canDrop · canPaste

connect API ​

getXxxProps() returns the host attributes of the matching part.

MemberType
acceptedFilesFile[]
remoteFilesFileUploadRemoteFile[]
allFilesFileUploadFile[]
draggingboolean
disabledboolean
invalidboolean
readOnlyboolean
requiredboolean
emptyboolean
maxFilesnumber
translationsFileUploadTranslations
fileKey(file: FileUploadFile) => string
fileHref(file: FileUploadFile) => string | undefined
getFileSizeText(file: FileUploadFile) => string
uploadOf(file: FileUploadFile) => FileUploadSnapshot | null
startUpload(file: File) => void
cancelUpload(file: File) => void
setFiles(files: File[]) => void
addFiles(files: File[]) => void
deleteFile(file: FileUploadFile) => void
clear() => void
openFilePicker() => void
getRootProps() => T['element']
getLabelProps() => T['label']
getDropzoneProps() => T['element']
getTriggerProps() => T['button']
getHiddenInputProps() => T['input']
getListProps() => T['element']
getItemProps(props: FileUploadItemProps) => T['element']
getItemNameProps(props: FileUploadItemProps) => T['element']
getItemLinkProps(props: FileUploadItemProps) => T['element']
getItemSizeTextProps(props: FileUploadItemProps) => T['element']
getItemPreviewProps(props: FileUploadItemProps) => T['element']
getItemProgressProps(props: FileUploadItemProps) => T['element']
getItemDeleteTriggerProps(props: FileUploadItemProps) => T['button']
getClearTriggerProps() => T['button']

Accessibility ​

Keyboard ​

Specification: W3C APG. Each row is a stable behavior id that the conformance tests cover; the conditions and effects are described on the Chinese page.

KeysBehavior
Tab / Shift+Tabfile-upload.kbd.tab
Enter / Spacefile-upload.kbd.open-dropzone
Enter / Spacefile-upload.kbd.open-trigger
Enter / Spacefile-upload.kbd.delete
Enter / Spacefile-upload.kbd.clear
Ctrl+V / Meta+Vfile-upload.kbd.paste
Enter / Spacefile-upload.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
dropzonearia-disabled'false' | 'true'
dropzonearia-invalid'true' | 'false'
dropzonearia-labelundefined | props.ariaLabel
dropzonearia-labelledbyid of the label part id of the dropzone part | id of the dropzone part
dropzonerole'button'
triggeraria-disabled'true' | undefined
hidden-inputaria-labelledbyid of the label part id of the dropzone part | id of the dropzone part
listrole'list'
itemrole'listitem'
item-linkaria-disabled'true' | undefined
item-previewaria-hidden'true'
item-progressaria-hidden'true'
item-delete-triggeraria-disabled'true' | undefined
item-delete-triggeraria-labellabel.deleteItem(file)
clear-triggeraria-disabled'true' | undefined
clear-triggeraria-labellabel.clearTrigger

Style reference ​

Skin ​

@xihan-ui/styles/file-upload.css is written against [data-scope="file-upload"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-file-upload in place of data-scope (same specificity) and sits in the xihan.components layer. Put overrides in xihan.overrides; the part selectors work as usual.

Data attributes ​

Produced by connect; valueless attributes are omitted while their condition does not hold.

PartAttributeValue
rootdata-disabled'' (present only while the condition holds)
rootdata-dragging'' (present only while the condition holds)
rootdata-empty'' (present only while the condition holds)
rootdata-invalid'' (present only while the condition holds)
rootdata-readonly'' (present only while the condition holds)
rootdata-required'' (present only while the condition holds)
labeldata-disabled'' (present only while the condition holds)
labeldata-required'' (present only while the condition holds)
dropzonedata-disabled'' (present only while the condition holds)
dropzonedata-dragging'' (present only while the condition holds)
dropzonedata-invalid'' (present only while the condition holds)
dropzonedata-readonly'' (present only while the condition holds)
triggerdata-disabled'' (present only while the condition holds)
triggerdata-pressed'' (present only while the condition holds)
triggerdata-readonly'' (present only while the condition holds)
triggerdata-xh-action-control''
triggerdata-xh-action-display'always'
triggerdata-xh-action-profile'text'
triggerdata-xh-action-size'md'
triggerdata-xh-action-variant'outline'
listdata-disabled'' (present only while the condition holds)
listdata-empty'' (present only while the condition holds)
listdata-instant'' (present only while the condition holds)
itemdata-disabled'' (present only while the condition holds)
itemdata-file-namefile.name
itemdata-file-sizeundefined | String(file.size) | String(file.size)
itemdata-remote'' (present only while the condition holds)
itemdata-stateuploadOf(file)?.status
item-namedata-disabled'' (present only while the condition holds)
item-linkdata-disabled'' (present only while the condition holds)
item-size-textdata-disabled'' (present only while the condition holds)
item-size-textdata-file-sizeundefined | String(file.size) | String(file.size)
item-previewdata-disabled'' (present only while the condition holds)
item-previewdata-file-type(isRemote(file) ? file.type ?? '' : file.type) || 'un…
item-progressdata-disabled'' (present only while the condition holds)
item-progressdata-stateupload?.status
item-delete-triggerdata-disabled'' (present only while the condition holds)
item-delete-triggerdata-pressed'' (present only while the condition holds)
item-delete-triggerdata-readonly'' (present only while the condition holds)
item-delete-triggerdata-xh-action-control''
item-delete-triggerdata-xh-action-display'always'
item-delete-triggerdata-xh-action-profile'icon'
item-delete-triggerdata-xh-action-size'xs'
item-delete-triggerdata-xh-action-variant'ghost'
clear-triggerdata-disabled'' (present only while the condition holds)
clear-triggerdata-empty'' (present only while the condition holds)
clear-triggerdata-pressed'' (present only while the condition holds)
clear-triggerdata-readonly'' (present only while the condition holds)
clear-triggerdata-xh-action-control''
clear-triggerdata-xh-action-display'always'
clear-triggerdata-xh-action-profile'text'
clear-triggerdata-xh-action-size'sm'
clear-triggerdata-xh-action-variant'ghost'

CSS variables ​

The public override slots, generated from what the standalone skin actually consumes.

VariablePartCSS propertyStateDefault from
--xh-file-upload-clear-bg-activeclear-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-file-upload-clear-bg-hoverclear-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-file-upload-clear-fgclear-triggercolordefault--xh-fg-muted
--xh-file-upload-clear-fg-hoverclear-triggercolordisabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-default
--xh-file-upload-clear-font-sizeclear-triggerfont-sizedefault--xh-_action-profile-font-size
--xh-file-upload-clear-gapclear-triggergapdefault--xh-_action-profile-gap
--xh-file-upload-clear-hclear-triggerblock-size
inline-size
default
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-file-upload-clear-pxclear-triggerpadding-inlinedefault--xh-_action-profile-padding-inline
--xh-file-upload-clear-radiusclear-triggerborder-radiusdefault--xh-shape-control
--xh-file-upload-delete-bg-activeitem-delete-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-file-upload-delete-bg-hoveritem-delete-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-file-upload-delete-fgitem-delete-triggercolordefault--xh-fg-muted
--xh-file-upload-delete-fg-hoveritem-delete-triggercolordisabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-danger-hover
--xh-file-upload-delete-radiusitem-delete-triggerborder-radiusdefault--xh-shape-control
--xh-file-upload-delete-sizeitem-delete-triggerblock-size
inline-size
default
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-file-upload-dropzone-bgdropzonebackgrounddefault--xh-bg-subtle
--xh-file-upload-dropzone-bg-disableddropzonebackgrounddisabled--xh-bg-subtle
--xh-file-upload-dropzone-bg-draggingdropzonebackgrounddragging--xh-bg-subtle-hover
--xh-file-upload-dropzone-bg-hoverdropzonebackgrounddisabled
dragging
hover
invalid
not([data-disabled], [data-readonly], [data-invalid], [data-dragging])
readonly
--xh-bg-subtle-hover
--xh-file-upload-dropzone-borderdropzoneborderdefault--xh-border-control
--xh-file-upload-dropzone-border-draggingdropzoneborder-colordragging--xh-bg-brand
--xh-file-upload-dropzone-border-focusdropzoneborder-colordisabled
dragging
focus-visible
invalid
not([data-disabled], [data-invalid], [data-dragging])
--xh-_tone
--xh-file-upload-dropzone-border-hoverdropzoneborder-colordisabled
dragging
hover
invalid
not([data-disabled], [data-readonly], [data-invalid], [data-dragging])
readonly
--xh-border-strong
--xh-file-upload-dropzone-border-invaliddropzoneborder-colorinvalid--xh-border-invalid
--xh-file-upload-dropzone-fgdropzonecolordefault--xh-fg-default
--xh-file-upload-dropzone-font-sizedropzonefont-sizedefault--xh-text-body-size
--xh-file-upload-dropzone-gapdropzonegapdefault--xh-space-2
--xh-file-upload-dropzone-min-hdropzonemin-block-sizedefault--xh-dropzone-min-h
--xh-file-upload-dropzone-pxdropzonepadding-inlinedefault--xh-space-4
--xh-file-upload-dropzone-pydropzonepadding-blockdefault--xh-space-5
--xh-file-upload-dropzone-radiusdropzoneborder-radiusdefault--xh-shape-control
--xh-file-upload-gaplabel
root
gap
margin-block-end
default--xh-space-3
--xh-file-upload-icon-sizeroot--xh-icon-sizedefault--xh-glyph-size-text
--xh-file-upload-item-bgitembackgrounddefault--xh-bg-subtle
--xh-file-upload-item-bg-erroritembackgroundhas(> [data-part='item-progress'][data-state='error'])
state=closed
state=error
--xh-bg-surface
--xh-file-upload-item-borderitemborderdefaulttransparent
--xh-file-upload-item-border-erroritemborder-colorhas(> [data-part='item-progress'][data-state='error'])
state=closed
state=error
transparent
--xh-file-upload-item-fgitemcolordefault--xh-fg-default
--xh-file-upload-item-fg-doneitembackground-colorhas(> [data-part='item-progress'][data-state='done'])
state=closed
state=done
--xh-fg-success
--xh-file-upload-item-fg-erroritem
item-name
background-color
color
has(> [data-part='item-progress'][data-state='error'])
state=closed
state=error
--xh-fg-danger
--xh-file-upload-item-font-sizeitemfont-sizedefault--xh-text-body-size
--xh-file-upload-item-gaplistgapdefault--xh-space-3
--xh-file-upload-item-inner-gapitemgapdefault--xh-space-3
--xh-file-upload-item-link-fgitem-linkcolordefault--xh-fg-brand
--xh-file-upload-item-link-fg-hoveritem-linkcolor@media (hover: hover)
disabled
hover
not([data-disabled])
--xh-fg-brand-strong
--xh-file-upload-item-link-radiusitem-linkborder-radiusdefault--xh-shape-inset
--xh-file-upload-item-link-underline-offsetitem-linktext-underline-offsetdefault--xh-space-0_5
--xh-file-upload-item-mark-sizeitemblock-size
inline-size
has(> [data-part='item-progress'][data-state='done'])
has(> [data-part='item-progress'][data-state='error'])
state=closed
state=done
state=error
--xh-control-indicator-size
--xh-file-upload-item-name-min-witem-namemin-inline-sizedefault--xh-control-min-w
--xh-file-upload-item-progress-fillitem-progressbackgrounddefault--xh-bg-brand
--xh-file-upload-item-progress-hitem-progressblock-sizedefault--xh-stroke-thick
--xh-file-upload-item-progress-radiusitem-progressborder-radiusdefault--xh-shape-pill
--xh-file-upload-item-progress-trackitem-progressbackgrounddefault--xh-bg-subtle
--xh-file-upload-item-progress-witem-progressinline-sizedefault--xh-control-h-md
--xh-file-upload-item-pxitempadding-inlinedefault--xh-space-3
--xh-file-upload-item-pyitempadding-blockdefault--xh-space-2
--xh-file-upload-item-radiusitemborder-radiusdefault--xh-shape-control
--xh-file-upload-label-fglabelcolordefault--xh-fg-muted
--xh-file-upload-label-fg-disabledlabelcolordisabled--xh-fg-muted
--xh-file-upload-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-file-upload-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-file-upload-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-file-upload-list-max-hlistmax-block-sizedefault--xh-viewport-h-md
--xh-file-upload-preview-bgitem-previewbackgrounddefaulttransparent
--xh-file-upload-preview-fgitem-previewcolordefault--xh-fg-brand
--xh-file-upload-preview-fg-imageitem-previewcolorfile-type=image/--xh-fg-brand
--xh-file-upload-preview-radiusitem-previewborder-radiusdefault--xh-shape-control
--xh-file-upload-preview-sizeitem-previewblock-size
inline-size
default--xh-glyph-size-sm
--xh-file-upload-size-fgitem-size-textcolordefault--xh-fg-subtle
--xh-file-upload-size-font-sizeitem-size-textfont-sizedefault--xh-text-caption-size
--xh-file-upload-trigger-bgtrigger--xh-ink-surface
background-color
default
xh-ink-surface
--xh-_action-variant-bg-rest
--xh-file-upload-trigger-bg-activetriggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-file-upload-trigger-bg-hovertriggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-file-upload-trigger-bordertriggerborderdefault--xh-_action-variant-border-rest
--xh-file-upload-trigger-fgtriggercolordefault
disabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-fg-hover
--xh-_action-variant-fg-pressed
--xh-_action-variant-fg-rest
--xh-file-upload-trigger-font-sizetriggerfont-sizedefault--xh-_action-profile-font-size
--xh-file-upload-trigger-font-weighttriggerfont-weightdefault--xh-text-label-weight
--xh-file-upload-trigger-gaptriggergapdefault--xh-_action-profile-gap
--xh-file-upload-trigger-htriggerblock-size
inline-size
default
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-file-upload-trigger-pxtriggerpadding-inlinedefault--xh-_action-profile-padding-inline
--xh-file-upload-trigger-radiustriggerborder-radiusdefault--xh-shape-control
--xh-file-upload-trigger-shadow-hovertriggerbox-shadowdisabled
hover
loading
not([data-disabled])
not([data-loading])
none

Released under The MIT License