如何从材料表中的自定义操作按钮中删除背景波纹效果?

问题描述 投票:1回答:1

我想从工具栏中创建的自定义按钮中删除背景波纹效果,而不是默认图标按钮。请参阅下面的截图,我想仅从导入和添加按钮中删除涟漪效果(圆圈效果),所有其他操作图标按钮应该正常运行。

                    <MaterialTable
                        columns={columns}
                        data={this.state.data}
                        icons={{
                            Add:()=><AddTaskButton onClick={()=>{}}/>
                        }}
                        actions={[
                            {
                                icon:this.renderImportButton,
                                isFreeAction:true
                            }
                        ]}
                        editable={{
                            onRowAdd: newData => this.onRowAdd(newData)
                        }}
                    />
material-ui material-table
1个回答
1
投票

您应该覆盖操作组件:

<MaterialTable
components={{
Action: props => <MyAction {...props}/>
}}
                        columns={columns}
                        data={this.state.data}
                        icons={{
                            Add:()=><AddTaskButton onClick={()=>{}}/>
                        }}
                        actions={[
                            {
                                icon:this.renderImportButton,
                                isFreeAction:true
                            }
                        ]}
                        editable={{
                            onRowAdd: newData => this.onRowAdd(newData)
                        }}
                    />

MyAction

import { Icon, IconButton, Tooltip } from '@material-ui/core';

class MyAction extends React.Component {
  render() {
    let action = this.props.action;
    if (typeof action === 'function') {
      action = action(this.props.data);
      if (!action) {
        return null;
      }
    }

    const handleOnClick = event => {
      if (action.onClick) {
        action.onClick(event, this.props.data);
        event.stopPropagation();
      }
    };

    const button = (
      <span>
        <IconButton
          color="inherit"
          disabled={action.disabled}
          disableRipple
          onClick={(event) => handleOnClick(event)}
        >
          {typeof action.icon === "string" ? (
            <Icon {...action.iconProps} fontSize="small">{action.icon}</Icon>
          ) : (
              <action.icon
                {...action.iconProps}
                disabled={action.disabled}                
              />
            )
          }
        </IconButton>
      </span>
    );

    if (action.tooltip) {
      return <Tooltip title={action.tooltip}>{button}</Tooltip>;
    } else {
      return button;
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.