Skip to content

CdsFileUpload

New in v4.0

A file upload zone: it accepts files by dragging, by pasting from the clipboard and through the system dialog, and shows the selection as a list with image previews. Around the zone the component gathers everything a form needs: a label, a description, messages and validation.

Storybook GitLab
Test coverage: 99% — good coverage
API in specs
214 / 214 props, events, slots and exposed members with a test
Test cases
149 unit · 7 browser · 9 planned
Known bugs
18 pinned by an it.fails test
Code coverage
99% lines · 90.9% branches measured in v4.0.0-alpha.13
A11y (axe)
16 recommendations in 13 stories measured in v4.0.0-alpha.11

For a compact file field in a form row use CdsFileInput; sending the files to the server is the job of CdsUploader.

Anatomy ​

The frame matches the other form fields (CdsTextInput): the label, the description, the messages and validation work the same way. What the component has of its own is the upload zone with an icon, a title and a browse button, and the list of the chosen files: every file gets a preview (for images), a name, a size and a remove button.

Variations ​

Choosing files ​

The basic case is a single file: drag it into the zone, paste it from the clipboard or pick it with the button. A repeated choice replaces the file.

The multiple prop allows choosing several files — they pile up as a list under the zone. clearable gives every one of them a remove button, show-size — the size.

Texts and the icon ​

Every caption of the zone is configurable: title — the heading, subtitle — the line with the file requirements (visible with size md and lg), browse-text — the text of the button, divider-text — the divider, icon — the icon in the center of the zone.

Sizes ​

The size prop controls the density of the zone: md is the default, lg adds air, and sm shrinks the zone to a compact row — the browse button is hidden and the whole area becomes clickable.

Layout ​

inset-file-list moves the list of the chosen files inside the zone — the component does not grow downwards as files are added. hide-browse removes the browse button: the zone is clickable as a whole, but say so in the title.

States ​

disabled blocks the component, readonly keeps the list visible but forbids changes, loading shows an indicator — while the files are going to the server, for example. error-messages puts the zone into the error state and shows the text under it.

Filtering by type ​

filter-by-type accepts MIME types, wildcard types and extensions separated by commas (image/*,.pdf). The files that do not fit never get into the model — the rejected event reports them: show the user what exactly was rejected and why.

Slots ​

The parts of the zone are replaced by the slots of the same name, and item redraws every file in the list: CdsFileUploadItem is available inside — it receives the props of the file automatically, it is enough to pass the handlers from the slot arguments.

Slot nameDescription
title / icon / dividerThe title, the icon and the divider of the zone
browseThe file browse button (props holds the click handler)
itemAn item of the list of the chosen files
singleThe only file with inset-file-list and without multiple
defaultYour own upload zone as a whole
inputThe native input type="file" for manual placement
loaderYour own loading indicator (with loading)
label / description / messagesThe texts of the frame — as in the other form fields

Guidelines ​

Scenarios ​

Applying for a job ​

The component takes part in CdsForm validation on a par with the other fields: rules receive the chosen files. Here the résumé is required and is accepted as a PDF only — filter-by-type cuts the foreign formats off, and the rules insure against an empty submission and a file that is too heavy.

filter-by-type="image/*" lets images through only — every one of them gets a preview in the list automatically. inset-file-list gathers what was uploaded inside the zone, and show-size helps keep an eye on the volume.

Uploading on selection ​

The files do not have to wait for the form submission — start the upload right away: watch the model, turn loading on for the duration of the request and confirm the result through messages. The request here is simulated with a timer.

API ​

CdsFileUpload ​

Props

NameTypeDefaultDescription
activeColorstring | undefined—Color of the component in its active state
appendIconIconValue | undefined—Icon in the append slot, after the content
baseColorstring | undefined—Color of the component in its inactive state
bgColorstring | undefined—Background color of the component
browseTextstring | undefined'$cds.fileUpload.browse'Text of the file browse button. Supports localization keys ($cds.fileUpload.browse).
centerAffixboolean | undefinedtrueVertically center the appendInner, prependInner, clearIcon and label elements.
clearableboolean | undefined—Allows removing the chosen files from the list.
colorstring | undefined—Component color
descriptionstring | undefined—Description of the component, shown under the label
disabledboolean | null | undefinednullDisabled state
dividerTextstring | undefined'$cds.fileUpload.divider'Text of the divider between the icon and the file browse button.
errorboolean | undefined—Puts the component into the error state
errorMessagesstring | readonly string[] | null | undefined[]Puts the component into the error state and passes custom error messages. They are merged with any checks defined in the rules prop. This field does not trigger validation.
filterByTypestring | undefined—Filtering of files by MIME type or extension (image/*,.pdf, for example). The rejected files do not get into the model.
focusedboolean | undefined—Controls the focus state of the component. When true, the component is considered focused and may apply the corresponding styles or behavior.
hideBrowseboolean | undefined—Hides the file browse button — the whole upload zone becomes clickable.
hideDetailsboolean | "auto" | undefined—Hides the details block (messages and hints). With the 'auto' value the block is hidden when there are no messages
hideMessagesboolean | undefined—Hide the messages under the input
hintstring | undefined—Hint text shown under the input
iconIconValue | undefined'upload'Icon in the center of the upload zone.
iconColorstring | boolean | undefined—Icon color. Accepts a boolean or a color string
idstring | undefined—Unique identifier of the component
insetFileListboolean | undefined—Shows the list of the chosen files inside the upload zone instead of under it.
labelstring | undefined—Label text of the component
loadingstring | boolean | undefined—Loading indicator for the component
maxErrorsstring | number | undefined1Maximum number of validation errors shown
maxWidthstring | number | undefined—Maximum component width
messagesstring | readonly string[] | undefined[]Messages shown under the input
minWidthstring | number | undefined—Minimum component width
modelValueFile | File[] | null | undefinednullThe chosen files. An array with multiple, a single File otherwise.
multipleboolean | undefined—Allows choosing several files.
namestring | undefined—Name of the input
persistentHintboolean | undefined—Always show the hint, not only on focus
prependIconIconValue | undefined—Icon in the prepend slot, before the content
readonlyboolean | null | undefinednullRead-only state
rulesreadonly ValidationRule[] | undefined[]Accepts an array of items of different types: functions, booleans and strings. Functions take the input value as an argument and must return either true / false, or a string with an error message. The input goes into the error state if a function returns false (or any value in the array is false) or is a string.
scrimstring | boolean | undefinedtrueDimming of the upload zone while files are being dragged over it.
showSizeShowSize | undefinedfalseShows the size of the file. A number sets the base for the human-readable conversion.
size"sm" | "md" | "lg" | undefined'md'Size of the upload zone. With sm the zone is shown as a compact row without the browse button and the divider.
subtitlestring | undefined—Subtitle under the file browse button. Shown with size md and lg only.
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme
titlestring | undefined'$cds.fileUpload.title'Title of the upload zone.
validateOnValidateOn | undefined—Changes the type of the event that triggers validation
validationValueany—Value used when applying the validation rules
widthstring | number | undefined—Component width

Events

NameTypeDescription
rejected[files: File[]]The files did not pass the filterByType filtering.
update:focused[focused: boolean]The focus state changed.
update:modelValue[files: File[]]The list of the chosen files changed.

Slots

NameTypeDescription
appendCdsInputSlotAdds an element after the input
browseCdsFileUploadBrowseSlotThe file browse button.
defaultanyFully replaces the upload zone with your own markup.
description{ description: string | undefined; props: Record<string, any>; }Default slot of the CdsDescription component
detailsCdsInputSlotSlot for custom content that lets you customize how the messages are displayed
divideranyDivider between the title and the file browse button.
iconanyIcon in the center of the upload zone.
input{ inputNode: VNode<RendererNode, RendererElement, { [key: string]: any; }>; }The native input[type=file], given out for manual placement in the markup.
itemCdsFileUploadFileSlotAn item of the list of the chosen files.
label{ label: string | undefined; props: Record<string, any>; }Default slot of the CdsLabel component
loaderLoaderSlotPropsThe loading indicator.
messageCdsMessageSlotSlot for customizing the content of a message
messagesCdsInputSlotSlot for custom content that lets you customize how the messages are displayed
prependCdsInputSlotAdds an element before the input
singleCdsFileUploadFileSlotThe only chosen file with insetFileList and without multiple.
titleanyTitle of the upload zone.

Exposed

NameTypeDescription
controlRefHTMLInputElement | undefinedRef to the native input[type=file] element — for opening the file dialog programmatically.
isDirtybooleanWhether the input is dirty
isDisabledbooleanWhether the input is disabled
isPurebooleanWhether the input is pure
isReadonlybooleanWhether the input is read-only
isValidboolean | nullWhether the input is valid
isValidatingbooleanWhether the input is being validated
reset() => Promise<void>Resets the input to its initial state
resetValidation() => Promise<void>Resets the validation of the input
validate(silent?: boolean) => Promise<string[]>Validates the input

CdsFileUploadDropzone ​

Props

NameTypeDefaultDescription
browseTextstring | undefined'$cds.fileUpload.browse'Text of the file browse button. Supports localization keys ($cds.fileUpload.browse).
clearableboolean | undefined—Allows removing the chosen files from the list.
colorstring | undefined—Background color of the surface
disabledboolean | null | undefinednullDisabled state
dividerTextstring | undefined'$cds.fileUpload.divider'Text of the divider between the icon and the file browse button.
errorboolean | undefined—Shows the upload zone in the error state.
heightstring | number | undefined—Component height
hideBrowseboolean | undefined—Hides the file browse button — the whole upload zone becomes clickable.
iconIconValue | undefined'upload'Icon in the center of the upload zone.
insetFileListboolean | undefined—Shows the list of the chosen files inside the upload zone instead of under it.
lengthstring | number | undefined150Length of the divider. Defaults to pixels.
locationAnchor | null | undefined—Position of the element relative to its container, for example "top left", "center", "bottom right".
maxHeightstring | number | undefined—Maximum component height
maxWidthstring | number | undefined—Maximum component width
minHeightstring | number | undefined—Minimum component height
minWidthstring | number | undefined—Minimum component width
modelValueFile[] | undefined[]The list of the chosen files. Used when CdsFileUploadDropzone is applied on its own.
multipleboolean | undefined—Allows choosing several files.
opacitystring | number | undefined—Opacity of the divider.
position"absolute" | "static" | "fixed" | "relative" | "sticky" | undefined—CSS positioning of the component — the value of the position property
readonlyboolean | null | undefinednullRead-only state
scrimstring | boolean | undefinedtrueDimming of the upload zone while files are being dragged over it.
showSizeShowSize | undefinedfalseShows the size of the file. A number sets the base for the human-readable conversion.
size"sm" | "md" | "lg" | undefined'md'Size of the upload zone. With sm the zone is shown as a compact row without the browse button and the divider.
subtitlestring | undefined—Subtitle under the file browse button. Shown with size md and lg only.
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
themestring | undefined—Component theme
thicknessstring | number | undefined—Thickness of the divider. Defaults to pixels.
titlestring | undefined'$cds.fileUpload.title'Title of the upload zone.
widthstring | number | undefined—Component width

Events

NameTypeDescription
click:browse[]The file browse button was pressed.
click:remove[index: number]Removal of a file by its index was requested.
drop[files: File[]]Files were dropped into the upload zone.

Slots

NameTypeDescription
browseCdsFileUploadBrowseSlotThe file browse button.
default{ isDragging: boolean; hasFiles: boolean; files: readonly File[]; props: { onClick: () => void; }; }Fully replaces the content of the upload zone.
divideranyDivider between the title and the file browse button.
iconanyIcon in the center of the upload zone.
inputanyThe native input[type=file].
itemCdsFileUploadFileSlotAn item of the list of the chosen files inside the upload zone.
loaderanyThe loading indicator.
singleCdsFileUploadFileSlotThe only chosen file with insetFileList and without multiple.
titleanyTitle of the upload zone.

CdsFileUploadItem ​

Props

NameTypeDefaultDescription
activeboolean | undefined—Forces the active state of the item
activeClassstring | undefined—Class applied to list items when they are in the active state
activeColorstring | undefined—Color of the component in its active state
appendAvatarstring | undefined—Avatar (image URL) shown after the item content
appendIconIconValue | undefined—Icon shown after the item content
baseColorstring | undefined—Color of the component in its inactive state
bgColorstring | undefined—Background color of the component
clearableboolean | undefined—Allows removing the file from the list.
colorstring | undefined—Component color
descriptionstring | number | boolean | undefined—Description of the list item shown below the title and the subtitle
disabledboolean | null | undefinednullDisabled state
exactboolean | undefined—If true, the active state applies only on an exact route match
fileFile | undefinednullThe file shown by the list item.
fileIconIconValue | undefined'file'Fallback icon for the files that have no preview.
heightstring | number | undefined—Component height
hrefstring | undefined—The href attribute of the link. When set, the component behaves as a regular link
indexnumber | undefined—Index of the item; used for keyboard navigation
linesfalse | "one" | "two" | "three" | undefined'two'Number of lines in the list items; affects their height. false turns off the fixed height
linkboolean | undefined—Turns the item into a clickable link. Detected automatically when href or to is set
maxHeightstring | number | undefined—Maximum component height
maxWidthstring | number | undefined—Maximum component width
minHeightstring | number | undefined—Minimum component height
minWidthstring | number | undefined—Minimum component width
navboolean | undefined—Applies navigation list styles (rounded active items)
prependAvatarstring | undefined—Avatar (image URL) shown before the item content
prependGapstring | number | undefined—Indent before the item content (reserves space for the prepend icon or avatar)
prependIconIconValue | undefined—Icon shown before the item content
replaceboolean | undefined—If true, navigation replaces the current history entry instead of pushing a new one
showSizeShowSize | undefinedfalseShows the size of the file instead of its MIME type.
slimboolean | undefined—Removes the inner paddings of the list and of the menu container: the list fills the available area completely
subtitlestring | number | boolean | undefined—Subtitle of the item shown below the title
tabindexstring | number | undefined—Value of the element tabindex attribute
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme
titlestring | number | boolean | undefined—Title of the item shown in the component
toLinkTo | undefined—Target route or route location object for RouterLink. When set, the component behaves as a RouterLink
valueany—Value of the item used for selection and activation in the list
widthstring | number | undefined—Component width

Events

NameTypeDescription
click[event: MouseEvent | KeyboardEvent]A click on the list item.
click:remove[]Removal of the file was requested.

Slots

NameTypeDescription
appendListItemSlotContent after the item text (in place of the append icon or avatar)
clear{ props: { onClick: () => void; }; }The file removal button.
defaultListItemSlotDefault content inside the item
descriptionListItemDescriptionSlotContent of the item description (shown below the title and the subtitle)
prependListItemSlotContent before the item text (in place of the prepend icon or avatar)
subtitleListItemSubtitleSlotContent of the item subtitle
titleListItemTitleSlotContent of the item title

CdsFileUploadList ​

Props

NameTypeDefaultDescription
activatableboolean | undefined—Allows items to be activated (highlighting the current item without selection mode)
activatedany—Identifiers of the active items (supports v-model through update:activated)
activeClassstring | undefined—Class applied to list items when they are in the active state
activeColorstring | undefined—Color of the component in its active state
activeStrategyActiveStrategyProp | undefined—Activation strategy for items (single, multiple, and so on)
baseColorstring | undefined—Color of the component in its inactive state
bgColorstring | undefined—Background color of the component
clearableboolean | undefined—Allows removing files from the list.
collapseIconIconValue | undefined—Icon shown on a collapsed group
colorstring | undefined—Component color
disabledboolean | null | undefinednullDisabled state
expandIconIconValue | undefined—Icon shown on an expanded group
filesFile[] | undefined—The list of files. Taken from the CdsFileUpload context by default.
filterableboolean | undefined—FOR INTERNAL USE ONLY Turns on filtering mode: the space key does not select an item but is used for typing. Applies to the CdsCombobox and CdsAutocomplete components
heightstring | number | undefined—Component height
indentstring | number | undefined—Indent size for nested item groups
itemChildrenSelectItemKey'children'Object field that holds the child items, or a function that returns them
itemPropsSelectItemKey'props'Object field that holds the props of the item, or a function that returns them
itemsany[] | undefined[]Array of items to display
itemsRegistrationItemsRegistrationType | undefined'render'Item registration strategy: render — as they are rendered, otherwise all at once
itemTitleSelectItemKey'title'Object field used as the item title, or a function that returns it
itemTypeSelectItemKey'type'Object field that defines the item type (item, divider, subheader), or a function that returns it
itemValueSelectItemKey'value'Object field used as the item value, or a function that returns it
linesfalse | "one" | "two" | "three" | undefinedfalseNumber of lines in the list items; affects their height. false turns off the fixed height
mandatoryboolean | undefined—Makes the selection mandatory: forbids clearing the selection of the last item
maxHeightstring | number | undefined—Maximum component height
maxWidthstring | number | undefined—Maximum component width
minHeightstring | number | undefined—Minimum component height
minWidthstring | number | undefined—Minimum component width
navboolean | undefined—Applies navigation list styles (rounded active items)
navigationIndexnumber | undefined—Index of the current item during keyboard navigation (supports v-model)
navigationStrategy"focus" | "track" | undefined'focus'Keyboard navigation strategy: focus — moves the focus, track — a virtual cursor
openedany—Identifiers of the expanded groups (supports v-model through update:opened)
openStrategyOpenStrategyProp | undefined'list'Expansion strategy for groups (list, single, multiple)
prependGapstring | number | undefined—Indent before the item content (reserves space for the prepend icon or avatar)
requiredboolean | undefined—Makes the selection mandatory: forbids clearing the selection of the last item
returnObjectboolean | undefined—Return an object in the model value instead of an array
selectableboolean | undefined—Allows items to be selected
selectedany—Identifiers of the selected items (supports v-model through update:selected)
selectStrategySelectStrategyProp | undefined'single-leaf'Selection strategy for items (single-leaf, leaf, independent, classic, and so on)
showSizeShowSize | undefinedfalseShows the size of every file.
slimboolean | undefined—Removes the inner paddings of the list and of the menu container: the list fills the available area completely
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme
valueComparatorValueComparator | undefined—Function that compares item values to determine the selected state
widthstring | number | undefined—Component width

Slots

NameTypeDescription
default{ files: readonly File[]; onClickRemove: (index: number) => void; }Fully replaces the content of the list.
itemCdsFileUploadFileSlotAn item of the list.