I created a custom <Tab/>
and I want to control its selection color by using the following code:
Sandbox Demo Code
export const Tab = styled(MuiTab)({ "&.Mui-selected": { color: "red" } });
However, I found:
1. Directly apply custom style components => The selected color is red
2.Wrapping custom style componentsin a self-created component => does not work, not even the default selected color
<Tabs value={value} variant="scrollable"> <Tab label="Tab" value={1} /> //選中顏色 = 默認(rèn)值 <TestTab label="TestTab" value={2} /> //選中顏色 = 默認(rèn)值(問題在這里) <Styled.Tab label="Styled.Tab" value={3} /> //選中顏色 = 紅色(好的,但我想包裝在自創(chuàng)建的組件中) </Tabs>
Is this normal behavior that MUI does not recognize self-created Tabs?
How to create a wrapper component that renders your custom Tab component this way TestTab
instead of using Styled.Tab
const TestTab = (props) => { return <Tab {...props} />; };