Skip to content

Commit

Permalink
📝 Upload action is not required prop
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Nov 19, 2018
1 parent 5705dc8 commit 13c25ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
25 changes: 9 additions & 16 deletions components/upload/demo/upload-manually.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,25 @@ class Demo extends React.Component {
}

render() {
const { uploading } = this.state;
const { uploading, fileList } = this.state;
const props = {
action: '//jsonplaceholder.typicode.com/posts/',
onRemove: (file) => {
this.setState(({ fileList }) => {
const index = fileList.indexOf(file);
const newFileList = fileList.slice();
this.setState((state) => {
const index = state.fileList.indexOf(file);
const newFileList = state.fileList.slice();
newFileList.splice(index, 1);
return {
fileList: newFileList,
};
});
},
beforeUpload: (file) => {
this.setState(({ fileList }) => ({
fileList: [...fileList, file],
this.setState(state => ({
fileList: [...state.fileList, file],
}));
return false;
},
fileList: this.state.fileList,
fileList,
};

return (
Expand All @@ -87,11 +86,11 @@ class Demo extends React.Component {
</Button>
</Upload>
<Button
className="upload-demo-start"
type="primary"
onClick={this.handleUpload}
disabled={this.state.fileList.length === 0}
disabled={fileList.length === 0}
loading={uploading}
style={{ marginTop: 16 }}
>
{uploading ? 'Uploading' : 'Start Upload' }
</Button>
Expand All @@ -102,9 +101,3 @@ class Demo extends React.Component {

ReactDOM.render(<Demo />, mountNode);
````

````css
.upload-demo-start {
margin-top: 16px;
}
````
2 changes: 1 addition & 1 deletion components/upload/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Uploading is the process of publishing information (web pages, text, pictures, v
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| accept | File types that can be accepted. See [input accept Attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept) | string | - |
| action | Required. Uploading URL | string\|(file) => `Promise` | - |
| action | Uploading URL | string\|(file) => `Promise` | - |
| directory | support upload whole directory ([caniuse](https://caniuse.com/#feat=input-file-directory)) | boolean | false |
| beforeUpload | Hook function which will be executed before uploading. Uploading will be stopped with `false` or a rejected Promise returned. **Warning:this function is not supported in IE9**| (file, fileList) => `boolean | Promise` | - |
| customRequest | override for the default xhr behavior allowing for additional customization and ability to implement your own XMLHttpRequest | Function | - |
Expand Down
2 changes: 1 addition & 1 deletion components/upload/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ title: Upload
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| accept | 接受上传的文件类型, 详见 [input accept Attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept) | string ||
| action | 必选参数, 上传的地址 | string\|(file) => `Promise` ||
| action | 上传的地址 | string\|(file) => `Promise` ||
| directory | 支持上传文件夹([caniuse](https://caniuse.com/#feat=input-file-directory)| boolean | false |
| beforeUpload | 上传文件之前的钩子,参数为上传的文件,若返回 `false` 则停止上传。支持返回一个 Promise 对象,Promise 对象 reject 时则停止上传,resolve 时开始上传。**注意:IE9 不支持该方法**| (file, fileList) => `boolean | Promise` ||
| customRequest | 通过覆盖默认的上传行为,可以自定义自己的上传实现 | Function ||
Expand Down

0 comments on commit 13c25ad

Please sign in to comment.