Search code examples
material-uimaterial-table

How to remove background ripple effect from custom action button in material-table?


I want to remove the background ripple effect from the custom buttons I have created in the toolbar in place of default icon buttons. Refer to screenshot below, I want to remove the ripple effect (the circle one) only from import and add buttons, all other action icon buttons should behave normally.

table screenshot

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

Solution

  • You should override the action component:

    <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;
        }
      }
    }