
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
@availity/mui-file-selector
Advanced tools
Availity MUI file-selector Component - part of the @availity/element design system
Availity MUI File Selector component to be used with @availity/element design system.
This package extends the MUI File Selector component: MUI File Selector Docs
Live demo and documentation in our Storybook
Availity standards for design and usage can be found in the Availity Design Guide
npm install @availity/element
yarn add @availity/element
This package has a few peer dependencies. Add @mui/material
& @emotion/react
to your project if not already installed.
npm install @availity/mui-file-selector
yarn add @availity/mui-file-selector
import { FileSelector } from '@availity/element';
import { FileSelector } from '@availity/mui-file-selector';
The FileSelector
component must be used inside a FormProvider
from react-hook-form
and a QueryClientProvider
from @tanstack/react-query
. Each provider has its own state that is necessary for using the component. The FormProvider
stores the Files
that are selected while the QueryClientProvider
has the upload
response data.
import React from 'react';
import { FileSelector } from '@availity/mui-file-selector';
const MyComponent = () => {
const methods = useForm({
defaultValues: {
myFiles: [] as File[],
},
});
const client = useQueryClient();
const files = methods.watch(props.name);
const handleOnSubmit = (values: Record<string, File[]>) => {
if (values.myFiles.length === 0) return;
const queries = client.getQueriesData<Upload>(['upload']);
const uploads = [];
for (const [, data] of queries) {
if (data) uploads.push(data);
}
};
return (
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(handleOnSubmit)}>
<FileSelector
name="myFiles"
bucketId="your-bucket-id"
customerId="your-customer-id"
clientId="your-client-id"
maxSize={5 * 1024 * 1024} // 5MB
maxFiles={3}
allowedFileTypes={['.pdf', '.doc', '.docx']}
/>
</form>
</FormProvider>
);
};
export default MyComponent;
Note: the following examples assume you have setup
react-hook-form
andreact-query
already
import React from 'react';
import { FileSelector } from '@availity/mui-file-selector';
const MyFileUploadComponent = () => {
const handleOnDrop = (acceptedFiles, fileRejections, event) => {
// Use this callback for interacting with the files before they are uploaded
};
const handleValidation = (file) => {
// Custom validation can be added with the `validator` prop.
// If an error fails validation here it should show up
// in the `fileRejections` array from `onDrop`.
//
// To return a custom error, return an object with a code
// and message.
// return { code: 'an-error', message: 'An error occurred' };
};
return (
<FileSelector
name="documentUpload"
bucketId="your-bucket-id"
customerId="your-customer-id"
clientId="your-client-id"
maxSize={10 * 1024 * 1024} // 10MB
allowedFileTypes={['.pdf', '.doc', '.docx']}
multiple={true}
maxFiles={5}
onDrop={handleOnDrop}
validator={handleValidation}
/>
);
};
export default MyFileUploadComponent;
It is possible to pass callbacks based on whether the upload finished successfully or there was an error.
import React from 'react';
import { FileSelector } from '@availity/mui-file-selector';
const MyFileUploadComponent = () => {
const handleOnSuccess = () => {
// Handle successful upload - e.g., show success message, update UI
};
const handleOnError = (error) => {
// Handle upload error - e.g., show error message, retry upload
};
return (
<FileSelector
name="documentUpload"
bucketId="your-bucket-id"
customerId="your-customer-id"
clientId="your-client-id"
maxSize={10 * 1024 * 1024} // 10MB
allowedFileTypes={['.pdf', '.doc', '.docx']}
multiple={true}
maxFiles={5}
uploadOptions={{
onSuccess: handleOnSuccess,
onError: handleOnError,
}}
/>
);
};
export default MyFileUploadComponent;
If you would like to show different information in each row then you are able to pass a custom FileRow
component. We recommend using the ListItem
component. The upload object from @availity/upload-core
, the options passed to its constructor, and the onRemoveFile
function will all be passed as props.
import React from 'react';
import { FileSelector } from '@availity/mui-file-selector';
import { ListItem } from '@availity/mui-list';
const FileRow = ({ upload, options, onRemoveFile }) => {
return <ListItem>Your code here</ListItem>;
};
const MyFileUploadComponent = () => {
return (
<FileSelector
name="documentUpload"
bucketId="your-bucket-id"
customerId="your-customer-id"
clientId="your-client-id"
maxSize={10 * 1024 * 1024} // 10MB
allowedFileTypes={['.pdf', '.doc', '.docx']}
multiple={true}
maxFiles={5}
customFileRow={FileRow}
/>
);
};
export default MyFileUploadComponent;
helpText
To provide custom help text, pass it as a child of the <FileSelector />
component. The help text should be formatted using the <Typography />
component with the 'caption'
variant.
import React from 'react';
import { FileSelector } from '@availity/mui-file-selector';
import { Typography } from '@availity/mui-typography';
const MyComponent = () => {
const methods = useForm({
defaultValues: {
myFiles: [] as File[],
},
});
const client = useQueryClient();
const files = methods.watch('myFiles);
const handleOnSubmit = (values: Record<string, File[]>) => {
if (values.myFiles.length === 0) return;
const queries = client.getQueriesData<Upload>(['upload']);
const uploads = [];
for (const [, data] of queries) {
if (data) uploads.push(data);
}
};
return (
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(handleOnSubmit)}>
<FileSelector
name="myFiles"
bucketId="your-bucket-id"
customerId="your-customer-id"
clientId="your-client-id"
maxSize={5 * 1024 * 1024} // 5MB
maxFiles={3}
allowedFileTypes={['.pdf', '.doc', '.docx']}
>
<Typography component="div" variant="caption">Here is some help text.</Typography>
</FileSelector>
</form>
</FormProvider>
);
};
export default MyComponent;
FAQs
Availity MUI file-selector Component - part of the @availity/element design system
The npm package @availity/mui-file-selector receives a total of 224 weekly downloads. As such, @availity/mui-file-selector popularity was classified as not popular.
We found that @availity/mui-file-selector demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.