-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(content-uploader): add onSelection callback (#3839) #3841
base: master
Are you sure you want to change the base?
feat(content-uploader): add onSelection callback (#3839) #3841
Conversation
Co-Authored-By: gregorywong@box.com <gregorywong@box.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
⚙️ Control Options:
|
@@ -42,7 +45,16 @@ const UploadInput = ({ | |||
data-testid="upload-input" | |||
directory={isFolderUpload ? '' : undefined} | |||
multiple={isMultiple} | |||
onChange={onChange} | |||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That comes handy when trying to upload files and their size exceeded 50mb (5010001000 as I figured Box doesn't like 5010241024 too much ;)).
Currnetly I handled it by observing classList string and reacting to the change after the onBeforeUpload
fired and contentExplorer changed it's button classes etc.
if (onSelection && files) { | ||
const shouldContinue = onSelection(files); | ||
if (!shouldContinue) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to clear out the file list other than doing files = ''
?
I know there's clearCache for remote but it'd be helpful to be able to reset the form other than clicking cancel.
I've found some information scattered around the web about this UI element but the documentation doesn't mention this event and even more intruiguing is that it doesn't really work as I would expect it to. I should be able to validate files (like exceeded size, fileType) before even allowing user to click "upload" button. That's not the case and I've already got davin to write some code: box/box-ui-elements#3841
Description
This PR adds an
onSelection
callback to the ContentUploader component to allow developers to control file selection before upload begins. This implements the suggestion from issue #3839.Changes
onSelection
prop to ContentUploader componentUsage
Testing
Link to Devin run: https://app.devin.ai/sessions/acbecd8da4154ad8aba8d8d81d7bd661