Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#2,018 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
25/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
停滞
技术栈
react, typescript
领域
frontend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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
主要语言
TypeScript
星标
2.7k
派生
248
平均合并
3 天 14 小时
30 天内合并 PR
83

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cloudscape-design/components 的其他 Issue

查看 cloudscape-design/components 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。