This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(chips): Don't trigger ripple from trailing icon #2286
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1d7ee3c
fix(chips): Don't trigger ripple from trailing icon
bonniezhou 85c9ee6
clean up
bonniezhou 0792944
Tests
bonniezhou 7acd812
emit custom event from trailing icon
bonniezhou ceb19dd
Add test
bonniezhou 99a82e9
Nits
bonniezhou a35f074
Merge branch 'master' into fix/chips/trailing-ripple
bonniezhou 865134a
Check that stopPropagation is called
bonniezhou 97b801b
Merge branch 'master' into fix/chips/trailing-ripple
bonniezhou 0441134
typo
bonniezhou dd0b8a2
Lint
bonniezhou 65fa1a9
Merge branch 'master' into fix/chips/trailing-ripple
bonniezhou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
import {assert} from 'chai'; | ||
import td from 'testdouble'; | ||
|
||
import {verifyDefaultAdapter} from '../helpers/foundation'; | ||
import {verifyDefaultAdapter, captureHandlers} from '../helpers/foundation'; | ||
import {setupFoundationTest} from '../helpers/setup'; | ||
import MDCChipFoundation from '../../../packages/mdc-chips/chip/foundation'; | ||
|
||
|
@@ -36,7 +36,9 @@ test('exports cssClasses', () => { | |
test('defaultAdapter returns a complete adapter implementation', () => { | ||
verifyDefaultAdapter(MDCChipFoundation, [ | ||
'addClass', 'removeClass', 'hasClass', | ||
'registerTrailingIconInteractionHandler', 'deregisterTrailingIconInteractionHandler', | ||
'registerInteractionHandler', 'deregisterInteractionHandler', 'notifyInteraction', | ||
'notifyTrailingIconInteraction', | ||
]); | ||
}); | ||
|
||
|
@@ -48,6 +50,11 @@ test('#init adds event listeners', () => { | |
|
||
td.verify(mockAdapter.registerInteractionHandler('click', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.registerInteractionHandler('keydown', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.registerTrailingIconInteractionHandler('click', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.registerTrailingIconInteractionHandler('keydown', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.registerTrailingIconInteractionHandler('touchstart', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.registerTrailingIconInteractionHandler('pointerdown', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.registerTrailingIconInteractionHandler('mousedown', td.matchers.isA(Function))); | ||
}); | ||
|
||
test('#destroy removes event listeners', () => { | ||
|
@@ -56,6 +63,11 @@ test('#destroy removes event listeners', () => { | |
|
||
td.verify(mockAdapter.deregisterInteractionHandler('click', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.deregisterInteractionHandler('keydown', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.deregisterTrailingIconInteractionHandler('click', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.deregisterTrailingIconInteractionHandler('keydown', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.deregisterTrailingIconInteractionHandler('touchstart', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.deregisterTrailingIconInteractionHandler('pointerdown', td.matchers.isA(Function))); | ||
td.verify(mockAdapter.deregisterTrailingIconInteractionHandler('mousedown', td.matchers.isA(Function))); | ||
}); | ||
|
||
test('#toggleActive adds mdc-chip--activated class if the class does not exist', () => { | ||
|
@@ -76,17 +88,28 @@ test('#toggleActive removes mdc-chip--activated class if the class exists', () = | |
|
||
test('on click, emit custom event', () => { | ||
const {foundation, mockAdapter} = setupTest(); | ||
const handlers = captureHandlers(mockAdapter, 'registerInteractionHandler'); | ||
const mockEvt = { | ||
type: 'click', | ||
}; | ||
let click; | ||
|
||
td.when(mockAdapter.registerInteractionHandler('click', td.matchers.isA(Function))).thenDo((evtType, handler) => { | ||
click = handler; | ||
}); | ||
|
||
foundation.init(); | ||
click(mockEvt); | ||
handlers.click(mockEvt); | ||
|
||
td.verify(mockAdapter.notifyInteraction()); | ||
}); | ||
|
||
test('on click in trailing icon, emit custom event', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might be able to save some code here by using (You can pass additional properties to the functions it returns, to be assigned to the event object.) Also, should we actually stub |
||
const {foundation, mockAdapter} = setupTest(); | ||
const handlers = captureHandlers(mockAdapter, 'registerTrailingIconInteractionHandler'); | ||
const mockEvt = { | ||
type: 'click', | ||
stopPropagation: td.func('stopPropagation'), | ||
}; | ||
|
||
foundation.init(); | ||
handlers.click(mockEvt); | ||
|
||
td.verify(mockAdapter.notifyTrailingIconInteraction()); | ||
td.verify(mockEvt.stopPropagation()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.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.
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.