diff --git a/demos/chips.html b/demos/chips.html
index 4c06dad05cf..6bcdcb7369b 100644
--- a/demos/chips.html
+++ b/demos/chips.html
@@ -78,6 +78,19 @@
Input Chips
cancel
+
+
@@ -243,12 +256,34 @@ Custom theme
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');
+ var trailingIconToggle = document.getElementById('toggle-trailing-icon');
[].forEach.call(chipSets, function(chipSet) {
mdc.chips.MDCChipSet.attachTo(chipSet);
});
var inputChipSetComponent = mdc.chips.MDCChipSet.attachTo(inputChipSetEl);
+ inputButton.addEventListener('click', addInputChip);
+ input.addEventListener('keydown', addInputChip);
+ deleteButton.addEventListener('click', deleteLastChip);
+ inputChipSetEl.addEventListener('MDCChip:removal', removeChip);
+ trailingIconToggle.addEventListener('change', resetInputChipSet);
+
+ function resetInputChipSet() {
+ inputChipSetComponent.destroy();
+ if (this.checked) {
+ inputChipSetComponent = new mdc.chips.MDCChipSet(inputChipSetEl, undefined, function(chipEl) {
+ const chip = new mdc.chips.MDCChip(chipEl);
+ chip.shouldRemoveOnTrailingIconClick = false;
+ return chip;
+ });
+ inputChipSetEl.addEventListener('MDCChip:trailingIconInteraction', confirmChipRemoval);
+ } else {
+ inputChipSetComponent = mdc.chips.MDCChipSet.attachTo(inputChipSetEl);
+ inputChipSetEl.removeEventListener('MDCChip:trailingIconInteraction', confirmChipRemoval);
+ }
+ }
+
function createChipEl(text, leadingIcon, trailingIcon) {
const chipTextEl = document.createElement('div');
chipTextEl.classList.add('mdc-chip__text');
@@ -267,7 +302,7 @@ Custom theme
}
function addInputChip(evt) {
- if ((evt.type === 'click' || evt.key === 'Enter' || evt.keyCode === 13) &&
+ if ((evt.type === 'click' || evt.key === 'Enter' || evt.keyCode === 13) &&
input.value !== '') {
var leadingIcon = document.querySelector('.input-leading-icon').cloneNode(true);
var trailingIcon = document.querySelector('.input-trailing-icon').cloneNode(true);
@@ -280,6 +315,12 @@ Custom theme
}
};
+ function confirmChipRemoval(evt) {
+ if (confirm('Are you sure you want to remove this chip?')) {
+ evt.detail.chip.beginExit();
+ }
+ }
+
function removeChip(evt) {
const root = evt.detail.root;
root && inputChipSetEl.removeChild(root);
@@ -290,11 +331,6 @@ Custom theme
const lastChip = inputChipSetComponent.chips[lastChipIndex];
lastChip.beginExit();
};
-
- inputButton.addEventListener('click', addInputChip);
- input.addEventListener('keydown', addInputChip);
- deleteButton.addEventListener('click', deleteLastChip);
- inputChipSetEl.addEventListener('MDCChip:removal', removeChip);
});