You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Material UI中FormControl包裹的Select组件下划线颜色

Solution to Customize Native Select Underline Color Without Switching to TextField

Got it! Since you're happy with your existing FormControl + native Select setup and just need to tweak the underline color, we can adapt the styling logic you already use for TextField directly here—no need to refactor to a different component.

Step 1: Update Your Styles Object

First, add a dedicated class for the Select's underline (you can reuse the exact pseudo-element styles from your TextField setup):

const styles = theme => ({
  // Reuse your existing label styles
  cssLabel: {
    color: themeStyle.textFieldUnderLineColor,
    "&.Mui-focused": {
      color: themeStyle.tabIndicatorProps,
    }
  },
  // Add this class for the Select underline
  selectUnderline: {
    '&:before': {
      borderBottomColor: themeStyle.textFieldUnderLineColor,
    },
    '&:after': {
      borderBottomColor: themeStyle.tabIndicatorProps,
    },
    '&:hover:before': {
      borderBottomColor: `${themeStyle.appBarRDbgk} !important`,
    },
  },
  // Keep your other existing styles (cssFocused, outlinedInput, etc.) if needed
})

Step 2: Apply the Style to Your Native Select

Modify your existing JSX to pass the new class to the Select's inputProps (this targets the underlying native input element that controls the underline):

<FormControl fullWidth>
  <InputLabel className={classes.cssLabel}>نوع فرم نامه</InputLabel>
  <Select
    TabIndicatorProps={{style: {backgroundColor: themeStyle.placeHolderTextColor}}}
    native
    autoFocus
    id="letILetTvCodeInt"
    onChange={this.handleChange}
    // Add this line to apply the custom underline style
    inputProps={{ className: classes.selectUnderline }}
  >
    {Tools.GetSelectOptions(this.state.LetType, 'LetTVCodeInt', 'LetTNameStr')}
  </Select>
</FormControl>

Why This Works

Since you're using the native prop on Select, Material-UI renders a standard HTML <select> element. The underline styling is controlled by pseudo-elements on this native input, so passing our custom class via inputProps lets us override MUI's default underline styles exactly like you did for TextField.

This keeps your existing code structure intact while achieving the exact underline color behavior you want.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 07:24:52