Skip to content

Commit

Permalink
Merge pull request #1323 from XiaoMi/hotfix/#1322
Browse files Browse the repository at this point in the history
fix: #1322
  • Loading branch information
solarjoker authored Nov 16, 2020
2 parents 9666dc2 + 14a22d3 commit f6d894f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 3.1.1

- 修复 `List` 组件导出问题 [#1314](https://github.com/XiaoMi/hiui/issues/1314)
- 修复 `Upload` onRemove 的问题 [#1322](https://github.com/XiaoMi/hiui/issues/1322)

## 3.1.0

Expand Down
9 changes: 4 additions & 5 deletions components/upload/hooks/useUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const useUpload = ({
useEffect(() => {
if (fileList) {
updateFileList(fileList)
fileListRef.current = fileList
}
}, [fileList])

Expand All @@ -34,19 +35,17 @@ const useUpload = ({
}
let result = true
if (onRemove) {
result = onRemove(file)
result = onRemove(file, [...fileListRef.current], index)
}
if (!fileList) {
const newFileList = [...fileListRef.current]
newFileList.splice(index, 1)
if (result === true) {
const newFileList = [...fileListRef.current]
newFileList.splice(index, 1)
fileListRef.current = newFileList
updateFileList(fileListRef.current)
} else if (result && typeof result.then === 'function') {
result.then((res) => {
if (res === true) {
const newFileList = [...fileListRef.current]
newFileList.splice(index, 1)
fileListRef.current = newFileList
updateFileList(fileListRef.current)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/components/upload.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import DemoCustom from '../../demo/upload/section-custom.jsx'
| 名称 | 说明 | 类型 | 参数 | 返回值 |
| ---------- | ------------------------ | ----------------------------------------------------------- | ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
| onChange | 上传回调 | (file: File, fileList: File[], response: object) => boolean | file: 上传的文件对象 <br/> fileList: 当前已上传文件列表集合 <br/> response: 响应对象 | boolean \| `Promise<boolean>`: 返回 false 则已上传文件列表不展示该文件 |
| onRemove | 删除上传的文件 | (file: File) => boolean | file: 移除的文件对象 | boolean \| `Promise<boolean>`: 返回 false 则不可删除,返回 true 时在前端删除文件 |
| onRemove | 删除上传的文件 | (file: File, fileList: File[], index: number) => boolean | file: 移除的文件对象, fileList: 当前已上传文件列表集合, index 索引 | boolean \| `Promise<boolean>`: 返回 false 则不可删除,返回 true 时在前端删除文件 |
| onDownload | 点击已上传的文件时的回调 | (file: File) => void | file: 点击的文件对象 | - |

## Type
Expand Down

0 comments on commit f6d894f

Please sign in to comment.