-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
test/unit/mdc-chips/mdc-chip.test.js
Outdated
@@ -39,6 +40,11 @@ function setupTest() { | |||
return {root, component}; | |||
} | |||
|
|||
test('get ripple returns MDCRipple instance', () => { | |||
const {component} = setupTest(); | |||
assert.isOk(component.ripple instanceof MDCRipple); |
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.
Ken had me replacing isOk
with isTrue
since isOk
is truthy.
test/unit/mdc-chips/mdc-chip.test.js
Outdated
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> |
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.
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 { |
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.
It seems like this should be nested in .mdc-chip__icon--leading
block above.
packages/mdc-chips/README.md
Outdated
@@ -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 |
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.
Nit: Trailing period consistency. Two descriptions have trailing punctuation, but most don't.
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.
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.
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.
Haha it's not annoying. Done.
…transition end event
packages/mdc-chips/README.md
Outdated
`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. |
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.
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); |
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.
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.
packages/mdc-chips/chip/adapter.js
Outdated
|
||
/** | ||
* Returns true if target has className, false otherwise. | ||
* @param {EventTarget} target |
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.
!EventTarget
packages/mdc-chips/chip/adapter.js
Outdated
* Returns true if target has className, false otherwise. | ||
* @param {EventTarget} target | ||
* @param {string} className | ||
*/ |
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.
Needs @return {boolean}
registerInteractionHandler: () => {}, | ||
deregisterInteractionHandler: () => {}, | ||
addClassToLeadingIcon: () => {}, | ||
eventTargetHasClass: () => {}, |
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.
Nit: move this below removeClassFromLeadingIcon to match adapter.js?
* @param {!Event} evt | ||
*/ | ||
handleTransitionEnd_(evt) { | ||
if (!(evt.propertyName === 'opacity')) { |
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.
Ease up on the parens... if (evt.propertyName !== 'opacity')
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.
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)) { |
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 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'], |
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.
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), |
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.
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.
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.
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
.
Known bug on IE/Edge filed separately: #2384 |
a34730a
to
8b799a5
Compare
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.
We should add BREAKING CHANGE: to the commit message for the renamed and added adapter APIs.
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.