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
[docs] Update code snippet in docs for custom color palette #32946
Merged
ZeeshanTamboli
merged 9 commits into
mui:master
from
ZeeshanTamboli:issue/32926-chip-crash-with-custom-color
Jun 23, 2022
Merged
[docs] Update code snippet in docs for custom color palette #32946
ZeeshanTamboli
merged 9 commits into
mui:master
from
ZeeshanTamboli:issue/32926-chip-crash-with-custom-color
Jun 23, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…me palette to avoid crash in alpha function
ZeeshanTamboli
added
component: chip
This is the name of the generic UI component, not the React module!
bug 🐛
Something doesn't work
labels
May 30, 2022
ZeeshanTamboli
changed the title
[Chip] Do not crash when a new color is added in theme and used
[Chip] Fix component crash when a new color is added in theme and used
May 30, 2022
mnajdova
reviewed
Jun 3, 2022
github-actions
bot
added
the
PR: out-of-date
The pull request has merge conflicts and can't be merged
label
Jun 17, 2022
github-actions
bot
removed
the
PR: out-of-date
The pull request has merge conflicts and can't be merged
label
Jun 20, 2022
ZeeshanTamboli
changed the title
[Chip] Fix component crash when a new color is added in theme and used
[Chip] Update code snippet in docs for custom color palette
Jun 22, 2022
ZeeshanTamboli
changed the title
[Chip] Update code snippet in docs for custom color palette
[docs] Update code snippet in docs for custom color palette
Jun 22, 2022
danilo-leal
reviewed
Jun 23, 2022
siriwatknp
approved these changes
Jun 23, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me.
2 tasks
Hi, I use jest reac test chip-component, it also show error "cannot read properties of undefined reading 'contrasttext'". |
This comment was marked as off-topic.
This comment was marked as off-topic.
Please open a separate issue with a reproduction. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug 🐛
Something doesn't work
component: chip
This is the name of the generic UI component, not the React module!
docs
Improvements or additions to the documentation
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #32926
contrastText
is undefined when a new custom color is added in theme without acontrastText
property. Contrast text color gets calculated for default paletteprimary
,secondary
etc. properties but not for custom color keys.The component crashes if the contrast text is used within
alpha
due to this particular line where it accesses on undefined.So we calculate the contrast text color withgetContrastText
before passing it to alpha when a custom color is provided in theme.palette.Before: https://codesandbox.io/s/chippropscoloroverrides-failing-example-forked-m4nvsl?file=/src/App.tsxNow: https://codesandbox.io/s/chippropscoloroverrides-failing-example-forked-1jlyfl?file=/src/App.tsxEdit: The docs are updated instead.
Docs preview: https://deploy-preview-32946--material-ui.netlify.app/material-ui/customization/palette/#providing-the-colors-directly