Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

fix(chips): Don't trigger ripple from trailing icon #2286

Merged
merged 12 commits into from
Feb 23, 2018

Conversation

bonniezhou
Copy link
Contributor

Resolves #2266.
A trailing icon should never trigger a ripple because its behaviour should always be separate from the chip's.

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.

LGTM, but one question below because stopPropagation should be a last resort.

We might want to revisit this at a later point in time if we can build something into ripple to assist with ignoring certain sub-elements instead.

* @param {!Event} evt
*/
handleTrailingIconInteraction_(evt) {
evt.stopPropagation();
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we eventually going to emit our own event on trailing icon click? I'm very wary of anything that adds stopPropagation with no alternative, since it tends to bite us later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! I updated it so the trailing icon emits a custom event.

In a later PR we'll capture this event in the chip and handle it if it's a remove icon.

@codecov-io
Copy link

codecov-io commented Feb 21, 2018

Codecov Report

Merging #2286 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2286      +/-   ##
==========================================
+ Coverage   99.04%   99.04%   +<.01%     
==========================================
  Files          99       99              
  Lines        3976     3999      +23     
  Branches      510      513       +3     
==========================================
+ Hits         3938     3961      +23     
  Misses         38       38
Impacted Files Coverage Δ
packages/mdc-chips/chip/constants.js 100% <ø> (ø) ⬆️
packages/mdc-chips/chip/index.js 82.75% <100%> (+7.75%) ⬆️
packages/mdc-chips/chip/foundation.js 100% <100%> (ø) ⬆️

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 1d131b4...65fa1a9. Read the comment docs.

@bonniezhou
Copy link
Contributor Author

Eventually having an option in ripple to ignore sub-elements sounds like a good idea.

@@ -120,6 +120,18 @@ test('#adapter.notifyInteraction emits ' +
td.verify(handler(td.matchers.anything()));
});

test('#adapter.notifyTrailingIconInteraction emits ' +
`${MDCChipFoundation.strings.INTERACTION_EVENT}`, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: You could omit the template string syntax here since it's already concatenated anyway

@@ -101,3 +102,22 @@ test('on click, emit custom event', () => {

td.verify(mockAdapter.notifyInteraction());
});

test('on click in trailing icon, emit custom event', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You might be able to save some code here by using test/unit/helpers.captureHandlers. Example usage within ripple: https://github.com/material-components/material-components-web/blob/master/test/unit/mdc-ripple/foundation-activation.test.js#L27

(You can pass additional properties to the functions it returns, to be assigned to the event object.)

Also, should we actually stub stopPropagation and test that it gets called? (I realize right now it needs to exist simply to not throw an error in the first place, but it could also test unintended behavior changes later.)

`notifyInteraction() => void` | Emits a custom event "MDCChip:interaction" denoting the chip has been interacted with, which bubbles to the parent `mdc-chip-set` element
`notifyTrailingIconInteraction() => void` | Emits a custom event "MDCChip:trailingIconInteraction" denoting the chip's trailing icon has been interacted with, which bubbles to the parent `mdc-chip-set` element
Copy link
Contributor

Choose a reason for hiding this comment

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

Double quotes -> backticks

@kfranqueiro kfranqueiro self-assigned this Feb 22, 2018
@@ -90,6 +119,17 @@ test('#adapter.notifyInteraction emits ' +
td.verify(handler(td.matchers.anything()));
});

test('#adapter.notifyTrailingIconInteraction emits ' + MDCChipFoundation.strings.INTERACTION_EVENT, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

INTERACTION_EVENT -> TRAILING_ICON_INTERACTION_EVENT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah nice catch!

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.

Hm, just noticed Travis CI failed due to lint (line length), is that still an issue?

@bonniezhou
Copy link
Contributor Author

Thanks, fixed!

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

Successfully merging this pull request may close these issues.

3 participants