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

Commit

Permalink
feat(chips): Expose method to begin chip exit animation (#2845)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonniezhou authored Jun 4, 2018
1 parent 5f4454a commit eb00fd3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions demos/chips.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ <h2>Input Chips</h2>
<button id="input-chip-set-button" class="mdc-button mdc-button--dense">
Add Input Chip
</button>
<button id="input-chip-set-delete-button" class="mdc-button mdc-button--dense">
Delete Last Chip
</button>
<div id="input-chip-set" class="mdc-chip-set mdc-chip-set--input">
<div class="demo-chip mdc-chip" tabindex="0">
<i class="material-icons mdc-chip__icon mdc-chip__icon--leading">face</i>
Expand Down Expand Up @@ -239,6 +242,7 @@ <h2>Custom theme</h2>
var chipSets = document.querySelectorAll('.mdc-chip-set:not(#input-chip-set)');
var input = document.getElementById('input-chip-set-input');
var inputButton = document.getElementById('input-chip-set-button');
var deleteButton = document.getElementById('input-chip-set-delete-button');

[].forEach.call(chipSets, function(chipSet) {
mdc.chips.MDCChipSet.attachTo(chipSet);
Expand Down Expand Up @@ -281,8 +285,15 @@ <h2>Custom theme</h2>
root && inputChipSetEl.removeChild(root);
}

function deleteLastChip() {
const lastChipIndex = inputChipSetComponent.chips.length - 1;
const lastChip = inputChipSetComponent.chips[lastChipIndex];
lastChip.beginExit();
};

inputButton.addEventListener('click', addInputChip);
input.addEventListener('keydown', addInputChip);
deleteButton.addEventListener('click', deleteLastChip);
inputChipSetEl.addEventListener('MDCChip:removal', removeChip);
});
</script>
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-chips/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Method Signature | Description
--- | ---
`get foundation() => MDCChipFoundation` | Returns the foundation
`isSelected() => boolean` | Proxies to the foundation's `isSelected` method
`beginExit() => void` | Begins the exit animation which leads to removal of the chip

Property | Value Type | Description
--- | --- | ---
Expand Down
9 changes: 8 additions & 1 deletion packages/mdc-chips/chip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {MDCRipple, MDCRippleFoundation} from '@material/ripple/index';

import MDCChipAdapter from './adapter';
import MDCChipFoundation from './foundation';
import {strings} from './constants';
import {strings, cssClasses} from './constants';

/**
* @extends {MDCComponent<!MDCChipFoundation>}
Expand Down Expand Up @@ -82,6 +82,13 @@ class MDCChip extends MDCComponent {
return this.foundation_.isSelected();
}

/**
* Begins the exit animation which leads to removal of the chip.
*/
beginExit() {
this.root_.classList.add(cssClasses.CHIP_EXIT);
}

/**
* @return {!MDCChipFoundation}
*/
Expand Down
6 changes: 6 additions & 0 deletions test/unit/mdc-chips/mdc-chip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,9 @@ test('#isSelected proxies to foundation', () => {
component.isSelected();
td.verify(mockFoundation.isSelected());
});

test(`#beginExit adds ${MDCChipFoundation.cssClasses.CHIP_EXIT} class`, () => {
const {component, root} = setupMockFoundationTest();
component.beginExit();
assert.isTrue(root.classList.contains(MDCChipFoundation.cssClasses.CHIP_EXIT));
});

0 comments on commit eb00fd3

Please sign in to comment.