FileUpload

File upload component

() => {
const handleUpload = (value) => {
console.log(value);
};
return (
<FileUpload onChange={handleUpload} supportedExtensions={['jpg', 'png']} />
);
};

Props

PropTypeDefaultDescription
onChange(FileList) => voidA function triggered when an item is selected. The single parameter will always be a FileList (an array) even when `multiple` is true.
supportedExtensionsstring[]Allowed extension types.
data-testidstring | undefineddata-testid added to the root element and added to the file input as `${testid}:input`
variant'sm' | 'md'smSmall or medium version of the component.
sampleFileTextstring | undefinedText shown for the 'sample' button.
onSampleFileClick() => voidClick event when the sample file text is clicked.
multipleboolean | undefinedfalseWhether or not more than 1 file can be uploaded at once.
onError(ErrorType) => voidEvent triggered when there is an error, ErrorType = 'invalid-extension' | 'multiple-files'.
errorboolean | undefinedDisplay a red border & red helper text when true.
helperTextstring | undefinedText shown below the field.

Examples

Basic

() => {
const handleUpload = (value) => {
console.log(value);
};
const handleClick = () => {
console.log('clicked');
};
const handleError = (type) => {
console.error('type: ', type);
}
return (
<FileUpload
onChange={handleUpload}
supportedExtensions={['jpg', 'png']}
data-testid="foobar"
variant="md"
sampleFileText="Download sample file"
onSampleFileClick={handleClick}
onError={handleError}
/>
);
};