Skip to content
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

Feature request: onRemovedFile (or something similar) #116

Open
jadenmazzone opened this issue Jan 19, 2022 · 5 comments
Open

Feature request: onRemovedFile (or something similar) #116

jadenmazzone opened this issue Jan 19, 2022 · 5 comments

Comments

@jadenmazzone
Copy link

jadenmazzone commented Jan 19, 2022

I can't find a way to know when a file has been removed after it has been uploaded. Here is my code below (very similar to your example). For the remove file button, I tried adding an onClick so that I could capture when the user removed the file - but this just overwrites the getRemoveFileProps. So wondering if there is currently a way to know if a file has been removed and if not maybe it could work in a similar way to "onUploadAccepted", but obviously gets called when the file is removed.

const { CSVReader } = useCSVReader();

<CSVReader
 

  onUploadAccepted={(results: any) => {
    console.log('---------------------------');
    console.log(results);
    console.log('---------------------------');
    setCsvData(results.data)
    setZoneHover(false);
  }}
  onDragOver={(event: DragEvent) => {
    event.preventDefault();
    setZoneHover(true);
  }}
  onDragLeave={(event: DragEvent) => {
    event.preventDefault();
    setZoneHover(false);
  }}
  
>
  {({
    getRootProps,
    acceptedFile,
    ProgressBar,
    getRemoveFileProps,
    Remove,
  }: any) => (
    <>
      <div
        {...getRootProps()}
        style={Object.assign(
          {},
          styles.zone,
          zoneHover && styles.zoneHover
        )}
      >
        {acceptedFile ? (
          <>
            <div style={styles.file}>
              <div style={styles.info}>
                <span style={styles.size}>
                  {formatFileSize(acceptedFile.size)}
                </span>
                <span style={styles.name}>{acceptedFile.name}</span>
              </div>
              <div style={styles.progressBar}>
                <ProgressBar />
              </div>
              <button
              
              
              {...getRemoveFileProps()}
                style={styles.remove}
                onMouseOver={(event: Event) => {
                  event.preventDefault();
                  setRemoveHoverColor(REMOVE_HOVER_COLOR_LIGHT);
                }}
                onMouseOut={(event: Event) => {
                  event.preventDefault();
                  setRemoveHoverColor(DEFAULT_REMOVE_HOVER_COLOR);
                }}
                
              >
                <Remove color={removeHoverColor} />
              </button>
            </div>
          </>
        ) : (
          'Drop CSV file here or click to upload'

        )}
      </div>
    </>
  )}
</CSVReader>

Version 4.0.0

@Angelfire
Copy link

Angelfire commented Jan 31, 2022

I updated yesterday and ran into the same problem... c.c. @Bunlong

@DanKellyRedcat
Copy link

We ran into the same issue, our solution was to revert back to v3 where you can use handleRemoveFile.

Would be good to have this in v4 or at least a workaround in the changelog

@rishipisipati
Copy link

Running into the same issue. It would be really nice if we could get a handleRemoveFile method to override.

@rishipisipati
Copy link

@Angelfire @DanKellyRedcat @jadenmazzone Not sure if you still need assistance, but this is what worked for me to preserve both the onClick method from removeFileProps and calling in my own code.

              {...getRemoveFileProps()}
                style={styles.remove}
                onMouseOver={(event: Event) => {
                  event.preventDefault();
                  setRemoveHoverColor(REMOVE_HOVER_COLOR_LIGHT);
                }}
                onMouseOut={(event: Event) => {
                  event.preventDefault();
                  setRemoveHoverColor(DEFAULT_REMOVE_HOVER_COLOR);
                }}
               onClick={(event: Event) => {
                 getRemoveFileProps.onClick(event);
                 // Your code here
               }}

@Prabashi
Copy link

Prabashi commented Apr 5, 2022

In @rishipisipati 's code, replacing

getRemoveFileProps.onClick(event); with

getRemoveFileProps().onClick(event); worked for me. Otherwise it gives an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants