Material ui 如何从材质表中的自定义操作按钮中删除背景涟漪效应?
我想从工具栏中创建的自定义按钮中删除背景涟漪效果,以代替默认图标按钮。 参考下面的屏幕截图,我想删除涟漪效应,仅从导入和添加按钮中删除圆形按钮,所有其他动作图标按钮应正常工作Material ui 如何从材质表中的自定义操作按钮中删除背景涟漪效应?,material-ui,material-table,Material Ui,Material Table,我想从工具栏中创建的自定义按钮中删除背景涟漪效果,以代替默认图标按钮。 参考下面的屏幕截图,我想删除涟漪效应,仅从导入和添加按钮中删除圆形按钮,所有其他动作图标按钮应正常工作 <MaterialTable columns={columns} data={this.state.data} icons={{
<MaterialTable
columns={columns}
data={this.state.data}
icons={{
Add:()=><AddTaskButton onClick={()=>{}}/>
}}
actions={[
{
icon:this.renderImportButton,
isFreeAction:true
}
]}
editable={{
onRowAdd: newData => this.onRowAdd(newData)
}}
/>
您应该覆盖动作组件:
<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)
}}
/>
我的行动
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;
}
}
}
您应该覆盖动作组件:
<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)
}}
/>
我的行动
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;
}
}
}
IconButton上的disableRipple不起作用,但为IconButton提供样式={{{backgroundColor:'transparent'}}},感谢@mehmet提供了这个覆盖示例。IconButton上的disableRipple不起作用,但为IconButton提供样式={{backgroundColor:'transparent'},感谢@mehmet提供了这个覆盖示例。