Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Link] Fix error for using custom palette with underline #44927

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/mui-material/src/Link/getTextDecoration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ describe('getTextDecoration', () => {
);
expect(() => getTextDecoration({ theme, ownerState: { color: 'yellow' } })).to.throw();
});

it('work with a custom palette', () => {
const customTheme = createTheme({
colorSchemes: {
light: {
palette: {
myColor: theme.palette.augmentColor({ color: { main: '#bbbbbb' } }),
},
},
dark: {
palette: {
myColor: theme.palette.augmentColor({ color: { main: '#aaaaaa' } }),
},
},
},
});
expect(getTextDecoration({ theme: customTheme, ownerState: { color: 'myColor' } })).to.equal(
'rgba(187, 187, 187, 0.4)',
);
});
});

describe('CSS variables', () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/mui-material/src/Link/getTextDecoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ const getTextDecoration = <T extends Theme>({
ownerState: { color: string };
}) => {
const transformedColor = ownerState.color;
const color = (getPath(theme, `palette.${transformedColor}`, false) ||
// check the `main` color first for a custom palette, then fallback to the color itself
const color = (getPath(theme, `palette.${transformedColor}.main`, false) ||
getPath(theme, `palette.${transformedColor}`, false) ||
ownerState.color) as string;
const channelColor = getPath(theme, `palette.${transformedColor}Channel`) as string | null;
const channelColor = (getPath(theme, `palette.${transformedColor}.mainChannel`) ||
getPath(theme, `palette.${transformedColor}Channel`)) as string | null;
if ('vars' in theme && channelColor) {
return `rgba(${channelColor} / 0.4)`;
}
Expand Down
Loading