4

I want to hide remove button in Antd Upload component only for files that meet certain criteria. I know remove icon can be disabled for every file using showRemoveIcon prop. But how can I do this for an individual file in the fileList

Johnson Cherian
  • 545
  • 1
  • 7
  • 21

3 Answers3

1

Try this:

handleRemoveId = id => {
    if(id === '-1') {
      return null;
    } else {
      return (
        <DeleteOutlined />
      )
    }
}

const uploadButton = (
 <div>
    <PlusOutlined />
    <div className="ant-upload-text">Upload</div>
 </div>
);

<Upload
  action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
  listType="picture-card"
  onPreview={this.handlePreview}
  onChange={this.handleChange}
>
  <div>
    {fileList.length && fileList.map(item => (
        <div style={{ position: 'relative' }}>
          <img src={item.url} alt="" height={80} />
          <span style={{ position: "absolute", left: '50%', top: '50%', transform: 'translate(-50%,-50%)', color: '#fff' }}>
            {this.handleRemoveId(item.uid)}
            <EyeOutlined />
           </span>
        </div>
     ))}
     {fileList.length < 8 ? uploadButton : null}
  </div>
</Upload>

You should handle all remove and visit by yourself, and add css alot, and check the remove icon by related uid you mean.

Note: It can write more better, Just was a hint and I dont know about your exact scenario.

Fatemeh Qasemkhani
  • 1,942
  • 1
  • 15
  • 25
1

This is not supported by antd currently. There is no support for per-file custom icons. I am having this same problem and submitted it as a feature request for ant-design at https://github.com/ant-design/ant-design/issues/26682

Michael Waddell
  • 279
  • 2
  • 6
0

Just try this approach to hide the preview and delete icons on image

.ant-upload-list-item-actions {
  display: none;
}
Akhil Raghav
  • 313
  • 1
  • 4
  • 16