Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Feature Request]: Add Event Parameter to Distinguish Adding / Removing Files from File Upload component

Aperta
#2,018 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Start at the FileUpload component's onChange prop and inspect how its event is produced when files are added or removed. Determine how the event can distinguish those actions, then check the component's existing tests for the expected behavior. Done means consumers can tell whether an onChange resulted from adding or removing files.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
Description

Hello,

When we add or remove files from the file upload component, the event that is passed in to the onChange prop is as follows:

cancelBubble : boolean,
cancelable : boolean,
defaultPrevented : boolean
detail: {value: Array(File)}

However, when uploading or remove files (by hitting on the X on one of the files), the event cannot tell them apart, therefore when trying to implement logic to prevent the use from uploading duplicated files, it is impossible to know whether they are uploading or removing.

This is how I am trying to add logic to the file upload, using react-hook-form

<Controller
                  name={formField.key as Path<TData>}
                  control={props.reactHookForm.control}
                  key={formField.key as string}
                  render={({ field, fieldState }) => (
                    <FormField
                      label={formField.label}
                      errorText={fieldState.error?.message}
                    >
                      <FileUpload
                        onChange={(e) => {                            
                          console.log(e);
                          let filesToUpload = e.detail.value; 
                          let skipFileCheck = false;                          
                          // check to make sure the file is allowed
                          if (formField.allowedTypes.includes(DocumentType.ANY))
                          {
                            skipFileCheck = true;
                          }
                          if (!skipFileCheck)
                          {
                            filesToUpload.forEach((file: File) => {                            
                            if (!formField.allowedTypes.includes(file.type as DocumentType)) {
                              // remove the file from the list
                              filesToUpload = filesToUpload.filter((f) => f !== file);                              
                            }                                                          
                            });  
                          }
                          
                          // remove any files that already exist in the field
                          if (field.value)
                          {
                            field.value.forEach((file: File) => {                            
                            filesToUpload = filesToUpload.filter((f) => f !== file);
                            });                            
                          }
                          
                          
                          field.onChange(filesToUpload);
                        }}
                        value={field.value ? field.value : []}
                        i18nStrings={{
                          uploadButtonText: e =>
                            e ? "Choose files" : "Choose file",
                          dropzoneText: e =>
                            e
                              ? "Drop files to upload"
                              : "Drop file to upload",
                          removeFileAriaLabel: e =>
                            `Remove file ${e + 1}`,
                          limitShowFewer: "Show fewer files",
                          limitShowMore: "Show more files",
                          errorIconAriaLabel: "Error"
                        }}
                        showFileLastModified
                        showFileSize        
                        multiple
                        showFileThumbnail
                        tokenLimit={3}
                        constraintText="Hint text for file requirements"
                      />
                    </FormField>
                  )}
                />
Code of Conduct
Lingua principale
TypeScript
Stelle
2.7k
Fork
248
Merge medio
3g 14h
PR unite (30g)
83

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudscape-design/components

Tutte le issue di cloudscape-design/components

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.