Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

fix(colors): handle null or undefined in md-colors #11673

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alirezamirian
Copy link
Contributor

@alirezamirian alirezamirian commented Mar 12, 2019

PR Checklist

Please check that your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added or this is not a bug fix / enhancement
  • Docs have been added, updated, or were not required

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Enhancement
[ ] Documentation content changes
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Described in #11672

Issue Number:
Fixes #11672

What is the new behavior?

If the md-colors expression evaluates to an object like { backgroundColor: undefined },
md-colors handles it and removes backgroundColor css property.

Does this PR introduce a breaking change?

[ ] Yes
[ ] No
[x] Not sure, but probably no.

Other information

Nothing

If md-colors expression evaluates to an object like `{ backgroundColor: undefined }`,
md-colors should handle it and remove backgroundColor css property.
@googlebot googlebot added the cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ label Mar 12, 2019
@Splaktar Splaktar self-assigned this Mar 13, 2019
@Splaktar Splaktar self-requested a review March 13, 2019 21:19
@Splaktar Splaktar added type: enhancement P4: minor Minor issues. May not be fixed without community contributions. labels Mar 13, 2019
Copy link
Member

@Splaktar Splaktar left a 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.

@@ -121,6 +121,9 @@
* @returns rgba color string
*/
function parseColor(color, contrast) {
if(!color) {
Copy link
Member

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.

@@ -121,6 +121,9 @@
* @returns rgba color string
Copy link
Member

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

@@ -171,6 +174,9 @@
* For the evaluated expression, extract the color parts into a hash map
*/
function extractColorOptions(expression) {
if(!expression) {
return undefined;
Copy link
Member

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).

@Splaktar Splaktar added in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs needs: unit tests This PR needs unit tests to cover the changes being proposed labels Mar 13, 2019
Splaktar added a commit that referenced this pull request Mar 13, 2019
mmalerba pushed a commit that referenced this pull request Mar 14, 2019
<!-- 
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
@Splaktar Splaktar added this to the - Backlog milestone Jul 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs needs: unit tests This PR needs unit tests to cover the changes being proposed P4: minor Minor issues. May not be fixed without community contributions. type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

colors: add support for null or undefined values
3 participants