2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MUIのアスタリスクの色だけを変えたりする(MUI v5)

Posted at

MUIでTextFieldにrequiredを付与したときにアスタリスクが表示されます。このアスタリスクを強調するために色を変えたいと思います。

image.png

僕はMUIのテーマ設定コンポーネントを作ってProviderとして使っていますのでこんな感じに追記してあげます。
createTheme()を使えば既存のMUIコンポーネントをオーバーライドできます。

ChangeTheme.ts
import React, { FC, ReactNode } from 'react'
import { GridProps } from '@mui/material'
import { createTheme, ThemeProvider } from '@mui/material/styles'

interface Props {
    children?: ReactNode
}

const ChangeTheme: FC<Props & GridProps> = ({ children }) => {
    const theme = createTheme({
        components: {
            // 追記
            MuiFormLabel: {
                styleOverrides: {
                    asterisk: { color: '#FF6A61' },
                },
            },
        },
    })

    return <ThemeProvider theme={theme}>{children}</ThemeProvider>
}

export default ChangeTheme


結果

こんな感じでまとめて適用できました〜〜〜
image.png

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?