Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 292049726
  • Loading branch information
material-web-copybara authored and joyzhong committed Jan 29, 2020
1 parent 8df1270 commit 26a3d10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/mdc-chips/chip/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ export class MDCChipFoundation extends MDCFoundation<MDCChipAdapter> {

private removeChip_(evt: MouseEvent|KeyboardEvent) {
evt.stopPropagation();
// Prevent default behavior for backspace on Firefox which causes a page
// navigation.
evt.preventDefault();
if (this.shouldRemoveOnTrailingIconClick_) {
this.beginExit();
}
Expand Down
8 changes: 8 additions & 0 deletions packages/mdc-chips/chip/test/foundation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,27 +379,31 @@ describe('MDCChipFoundation', () => {
const mockEvt = {
type: 'click',
stopPropagation: jasmine.createSpy('stopPropagation'),
preventDefault: jasmine.createSpy('preventDefault'),
key: '',
};

foundation.handleTrailingIconInteraction(mockEvt);
expect(mockAdapter.notifyTrailingIconInteraction)
.toHaveBeenCalledTimes(1);
expect(mockEvt.stopPropagation).toHaveBeenCalledTimes(1);
expect(mockEvt.preventDefault).toHaveBeenCalledTimes(1);

mockEvt.type = 'keydown';
mockEvt.key = ' ';
foundation.handleTrailingIconInteraction(mockEvt);
expect(mockAdapter.notifyTrailingIconInteraction)
.toHaveBeenCalledTimes(2);
expect(mockEvt.stopPropagation).toHaveBeenCalledTimes(2);
expect(mockEvt.preventDefault).toHaveBeenCalledTimes(2);

mockEvt.type = 'keydown';
mockEvt.key = 'Enter';
foundation.handleTrailingIconInteraction(mockEvt);
expect(mockAdapter.notifyTrailingIconInteraction)
.toHaveBeenCalledTimes(3);
expect(mockEvt.stopPropagation).toHaveBeenCalledTimes(3);
expect(mockEvt.preventDefault).toHaveBeenCalledTimes(3);
});

it(`#handleTrailingIconInteraction adds ${
Expand All @@ -409,13 +413,15 @@ describe('MDCChipFoundation', () => {
const mockEvt = {
type: 'click',
stopPropagation: jasmine.createSpy('stopPropagation'),
preventDefault: jasmine.createSpy('preventDefault'),
};

foundation.handleTrailingIconInteraction(mockEvt);

expect(foundation.getShouldRemoveOnTrailingIconClick()).toBe(true);
expect(mockAdapter.addClass).toHaveBeenCalledWith(cssClasses.CHIP_EXIT);
expect(mockEvt.stopPropagation).toHaveBeenCalled();
expect(mockEvt.preventDefault).toHaveBeenCalled();
});

it(`#handleTrailingIconInteraction does not add ${
Expand All @@ -426,6 +432,7 @@ describe('MDCChipFoundation', () => {
const mockEvt = {
type: 'click',
stopPropagation: jasmine.createSpy('stopPropagation'),
preventDefault: jasmine.createSpy('preventDefault'),
};

foundation.setShouldRemoveOnTrailingIconClick(false);
Expand All @@ -435,6 +442,7 @@ describe('MDCChipFoundation', () => {
expect(mockAdapter.addClass)
.not.toHaveBeenCalledWith(cssClasses.CHIP_EXIT);
expect(mockEvt.stopPropagation).toHaveBeenCalled();
expect(mockEvt.preventDefault).toHaveBeenCalled();
});

it('#handleKeydown emits custom event with appropriate keys', () => {
Expand Down

0 comments on commit 26a3d10

Please sign in to comment.