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

feat(chips): Replace leading icon with checkmark in selected filter chips #2320

Merged
merged 47 commits into from
Mar 13, 2018

Conversation

bonniezhou
Copy link
Contributor

@bonniezhou bonniezhou commented Feb 28, 2018

Fixes #2009.
When a filter chip is selected, add a checkmark as the leading icon of the filter chip. If a leading icon already exists, replace it with the checkmark.

Known bug: the ripple doesn't extend all the way to the end of the chip when the chip's width is animating. Filed #2334 to be fixed in a later PR.

@codecov-io
Copy link

codecov-io commented Mar 2, 2018

Codecov Report

Merging #2320 into master will increase coverage by 0.02%.
The diff coverage is 96.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2320      +/-   ##
==========================================
+ Coverage   98.86%   98.88%   +0.02%     
==========================================
  Files         100      100              
  Lines        4123     4144      +21     
  Branches      528      535       +7     
==========================================
+ Hits         4076     4098      +22     
+ Misses         47       46       -1
Impacted Files Coverage Δ
packages/mdc-chips/chip/constants.js 100% <ø> (ø) ⬆️
packages/mdc-chips/chip/index.js 91.89% <100%> (+9.13%) ⬆️
packages/mdc-chips/chip/foundation.js 98.18% <95.23%> (-1.82%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 567deec...1a84c1c. Read the comment docs.

@@ -39,6 +40,11 @@ function setupTest() {
return {root, component};
}

test('get ripple returns MDCRipple instance', () => {
const {component} = setupTest();
assert.isOk(component.ripple instanceof MDCRipple);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ken had me replacing isOk with isTrue since isOk is truthy.

test('#adapter.addClassToLeadingIcon adds a class to the leading icon element', () => {
const {root, component} = setupTest();
const leadingIcon = bel`
<i class="material-icons mdc-chip__icon mdc-chip__icon--leading">face</i>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to move this to a common area since it's used in 4 tests?

opacity: 1;
}

.mdc-chip__icon--leading + .mdc-chip__checkmark {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this should be nested in .mdc-chip__icon--leading block above.

@@ -86,6 +113,8 @@ CSS Class | Description
`mdc-chip__icon` | Optional. Indicates an icon in the chip
`mdc-chip__icon--leading` | Optional. Indicates a leading icon in the chip
`mdc-chip__icon--trailing` | Optional. Indicates a trailing icon in the chip
`mdc-chip__checkmark` | Optional. Indicates the checkmark SVG element in a filter chip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Trailing period consistency. Two descriptions have trailing punctuation, but most don't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to be annoying, but any time we have multiple sentences already, the last one should end with a period too, so technically we should have periods at the end of all of these. That can be handled separately from this PR though, at least this is consistent for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha it's not annoying. Done.

`deregisterInteractionHandler(evtType: string, handler: EventListener) => void` | Deregisters an event listener on the root element
`addClassToLeadingIcon(className: string) => void` | Adds a class to the leading icon element
`removeClassFromLeadingIcon(className: string) => void` | Removes a class from the leading icon element
`eventTargetHasClass(target: EventTarget, className: string) => boolean` | Returns true if target has className, false otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent period here while the others don't have one

@@ -61,6 +61,10 @@
@include mdc-theme-prop(color, $color);
}
}

.mdc-chip__checkmark-path {
@include mdc-theme-prop(stroke, $color);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followed up offline about this and realized that it kinda doesn't matter whether it were to use currentColor or not, since either way this mixin is the only place we're setting up this color.


/**
* Returns true if target has className, false otherwise.
* @param {EventTarget} target
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!EventTarget

* Returns true if target has className, false otherwise.
* @param {EventTarget} target
* @param {string} className
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs @return {boolean}

registerInteractionHandler: () => {},
deregisterInteractionHandler: () => {},
addClassToLeadingIcon: () => {},
eventTargetHasClass: () => {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move this below removeClassFromLeadingIcon to match adapter.js?

* @param {!Event} evt
*/
handleTransitionEnd_(evt) {
if (!(evt.propertyName === 'opacity')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ease up on the parens... if (evt.propertyName !== 'opacity')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow major brain fart on the opposite of === 😛

this.adapter_.hasClass(cssClasses.SELECTED)) {
this.adapter_.addClassToLeadingIcon(cssClasses.HIDDEN_LEADING_ICON);
} else if (this.adapter_.eventTargetHasClass(evt.target, cssClasses.CHECKMARK) &&
!this.adapter_.hasClass(cssClasses.SELECTED)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're trying to line this line up after the opening paren, this needs one more space

const mockEvt = {
type: 'transitionend',
target: {
classList: ['mdc-chip__checkmark'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this even necessary here and in the next test, when you're mocking the adapter calls? It wasn't necessary in the previous 2 tests...

this.leadingIcon_.classList.remove(className);
}
},
eventTargetHasClass: (target, className) => target.classList.contains(className),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out classList doesn't exist on SVG elements in IE 11 :( also I don't think className behaves the same as on other DOM elements either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapped a div around the SVG to make IE 11 happy...the div now has the mdc-chip__checkmark class and the SVG has mdc-chip__checkmark-svg.

@bonniezhou
Copy link
Contributor Author

Known bug on IE/Edge filed separately: #2384

Copy link
Contributor

@kfranqueiro kfranqueiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add BREAKING CHANGE: to the commit message for the renamed and added adapter APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mdc-chip-set--filter
4 participants