[Feature Request]: Add Event Parameter to Distinguish Adding / Removing Files from File Upload component
维护者通常 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 内容生成。
描述
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
- I agree to follow this project's Code of Conduct
- I checked the current issues for duplicate requests
- 主要语言
- TypeScript
- 星标
- 2.7k
- 派生
- 248
- 平均合并
- 3 天 14 小时
- 30 天内合并 PR
- 83
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cloudscape-design/components 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
cloudscape-design/components#5184 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
cloudscape-design/components#5152 · 1 条评论 ·
维护者通常 2 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 15/100
cloudscape-design/components#5149 · 1 条评论 ·
维护者通常 2 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 45/100
cloudscape-design/components#5117 · 2 条评论 ·
维护者通常 2 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
cloudscape-design/components#5106 · 1 条评论 ·
维护者通常 2 天内回复
查看 cloudscape-design/components 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
MoonshotAI/kimi-code#4398 ·
维护者通常 1 天内回复
-
pending triage
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
package-lock.json : les binaires natifs macOS et Linux de unrs-resolver ont disparu depuis #1823未关闭bug dependencies
难度 2/5 1-3 小时 新手友好度 70/100
AxaFrance/design-system#2064 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 85/100