-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(colors): handle null or undefined in md-colors #11673
base: master
Are you sure you want to change the base?
Conversation
If md-colors expression evaluates to an object like `{ backgroundColor: undefined }`,
md-colors should handle it and remove backgroundColor css property.
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.
Thank you for your contribution. I had a few minor comments. Additionally, we'll want to add some tests to verify this functionality in https://github.com/angular/material/blob/fca9d1d52740765f522da1f47e269dd3a496974d/src/components/colors/colors.spec.js.
| * @returns rgba color string | ||
| */ | ||
| function parseColor(color, contrast) { | ||
| if(!color) { |
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.
Please run npm run lint -- --fix to get these changes to pass the lint checks.
| * Return the parsed color | ||
| * @param color hashmap of color definitions | ||
| * @param contrast whether use contrast color for foreground | ||
| * @returns rgba color string |
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.
This should be updated to be
* @returns {string} rgba color string or empty string| */ | ||
| function extractColorOptions(expression) { | ||
| if(!expression) { | ||
| return undefined; |
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.
If this is going to start returning undefined, then we need to make sure that callers like interpolateColors() on lines 154 and 156 don't call parseColor(undefined).
<!-- Filling out this template is required! Do not delete it when submitting a Pull Request! Without this information, your Pull Request may be auto-closed. --> ## PR Checklist Please check that your PR fulfills the following requirements: - [x] The commit message follows [our guidelines](https://github.com/angular/material/blob/master/.github/CONTRIBUTING.md#-commit-message-format) - [x] Tests for the changes have been added or this is not a bug fix / enhancement - [x] Docs have been added, updated, or were not required ## PR Type What kind of change does this PR introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [ ] Bugfix [ ] Enhancement [ ] Documentation content changes [ ] Code style update (formatting, local variables) [x] Refactoring (no functional changes, no api changes) [ ] Build related changes [ ] CI related changes [ ] Infrastructure changes [ ] Other... Please describe: ``` ## What is the current behavior? The Closure types / JSDoc in `md-colors` and `util/colors` is very inconsistent and/or missing. There are quite a few typos. <!-- Please describe the current behavior that you are modifying and link to one or more relevant issues. --> Issue Number: Relates to #11673 ## What is the new behavior? - Clean up typos. - The Closure types / JSDoc in `md-colors` and `util/colors` are much more helpful and organized. ## Does this PR introduce a breaking change? ``` [ ] Yes [x] No ``` <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. --> <!-- Note that breaking changes are highly unlikely to get merged to master unless the validation is clear and the use case is critical. --> ## Other information
PR Checklist
Please check that your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Described in #11672
Issue Number:
Fixes #11672
What is the new behavior?
If the
md-colorsexpression evaluates to an object like{ backgroundColor: undefined },md-colorshandles it and removesbackgroundColorcss property.Does this PR introduce a breaking change?
Other information
Nothing