You need to enable JavaScript to run this app. 如何覆盖Material-UI中Chip组件的deleteIcon/cancelIcon配置?
优惠活动
大模型
产品
解决方案
定价
更多

如何覆盖Material-UI中Chip组件的deleteIcon/cancelIcon配置?

解决方案

你可以通过自定义主题配置实现全局覆盖,以下是两种适配不同需求的实现方案:

方案1:仅修改Autocomplete内部生成的Chip删除图标(不影响全局其他Chip)

该方案只会作用于多选Autocomplete内部自动生成的Chip,不会改动项目中其他单独引用的Chip组件:

import { createTheme } from '@mui/material/styles';
import Chip from '@mui/material/Chip';
// 替换为你想要使用的目标图标组件
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';

const customTheme = createTheme({
  components: {
    MuiAutocomplete: {
      defaultProps: {
        // 重写多选模式下默认的标签渲染逻辑
        renderTags: (value, getTagProps) =>
          value.map((option, index) => (
            <Chip
              {...getTagProps({ index })}
              label={option.label}
              // 替换默认删除图标
              deleteIcon={<DeleteOutlineIcon />}
            />
          )),
      },
    },
  },
});

如果你的选项值展示字段不是label,对应修改label属性的取值逻辑即可。

方案2:全局修改所有Chip的删除图标(包含Autocomplete内部生成的)

如果你希望项目中所有Chip组件的删除图标统一替换,使用该方案更简便:

import { createTheme } from '@mui/material/styles';
// 替换为你想要使用的目标图标组件
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';

const customTheme = createTheme({
  components: {
    MuiChip: {
      defaultProps: {
        deleteIcon: <DeleteOutlineIcon />,
      },
    },
  },
});

Autocomplete组件内部Chip效果截图

内容的提问来源于stack exchange,提问作者franciscojs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.13 14:00:01