Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(chips): fixes issue when removing chips via button
Browse files Browse the repository at this point in the history
Closes #74
  • Loading branch information
Robert Messerle committed Apr 9, 2015
1 parent 4f43d6b commit 59d359c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/components/chips/js/chipRemoveDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
function postLink(scope, element, attr, ctrl) {
element.on('click', function(event) {
scope.$apply(function() {
ctrl.removeChip(scope.$index);
ctrl.removeChip(scope.$$replacedScope.$index);
});
});

Expand Down
1 change: 1 addition & 0 deletions src/components/chips/js/chipTranscludeDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
function link (scope, element, attr) {
var ctrl = scope.$parent.$mdChipsCtrl,
newScope = ctrl.parent.$new(false, ctrl.parent);
newScope.$$replacedScope = scope;
newScope.$chip = scope.$chip;
newScope.$mdChipsCtrl = ctrl;
element.html(ctrl.$scope.$eval(attr.mdChipTransclude));
Expand Down
29 changes: 3 additions & 26 deletions src/components/chips/js/chipsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
.module('material.components.chips')
.controller('MdChipsCtrl', MdChipsCtrl);



/**
* Controller for the MdChips component. Responsible for adding to and
* removing from the list of chips, marking chips as selected, and binding to
Expand Down Expand Up @@ -82,7 +80,6 @@
}.bind(this));
}


/**
* Handles the keydown event on the input element: <enter> appends the
* buffer to the chip list, while backspace removes the last chip in the list
Expand Down Expand Up @@ -122,7 +119,6 @@
return useSecondary ? this.placeholder : this.secondaryPlaceholder;
};


/**
* Removes chip at {@code index} and selects the adjacent chip.
* @param index
Expand All @@ -133,15 +129,13 @@
this.selectAndFocusChip(selIndex);
};


/**
* Sets the selected chip index to -1.
*/
MdChipsCtrl.prototype.resetSelectedChip = function() {
this.selectedChip = -1;
};


/**
* Gets the index of an adjacent chip to select after deletion. Adjacency is
* determined as the next chip in the list, unless the target chip is the
Expand All @@ -157,7 +151,6 @@
(index == len) ? index -1 : index;
};


/**
* Append the contents of the buffer to the chip list. This method will first
* call out to the md-on-append method, if provided
Expand All @@ -171,7 +164,6 @@
this.items.push(newChip);
};


/**
* Sets whether to use the md-on-append expression. This expression is
* bound to scope and controller in {@code MdChipsDirective} as
Expand All @@ -183,7 +175,6 @@
this.useMdOnAppend = true;
};


/**
* Gets the input buffer. The input buffer can be the model bound to the
* default input item {@code this.chipBuffer}, the {@code selectedItem}
Expand All @@ -198,7 +189,6 @@
this.userInputElement[0].value;
};


/**
* Resets the input buffer for either the internal input or user provided input element.
*/
Expand All @@ -215,7 +205,6 @@
}
};


/**
* Removes the chip at the given index.
* @param index
Expand All @@ -224,27 +213,18 @@
this.items.splice(index, 1);
};


/**
* Selects the chip at `index`,
* @param index
*/
MdChipsCtrl.prototype.selectChipSafe = function(index) {
if (this.items.length == 0) {
this.selectChip(-1);
return;
}

if (index < 0) {
index = 0;
} else if (index > this.items.length - 1) {
index = this.items.length - 1;
}
if (!this.items.length) return this.selectChip(-1);
index = Math.max(index, 0);
index = Math.min(index, this.items.length - 1);
this.selectChip(index);
this.focusChip(index);
};


/**
* Marks the chip at the given index as selected.
* @param index
Expand All @@ -257,7 +237,6 @@
}
};


/**
* Selects the chip at `index` and gives it focus.
* @param index
Expand All @@ -269,15 +248,13 @@
}
};


/**
* Call `focus()` on the chip at `index`
*/
MdChipsCtrl.prototype.focusChip = function(index) {
this.$element[0].querySelector('md-chip[index="' + index + '"] .md-chip-content').focus();
};


/**
* Configures the required interactions with the ngModel Controller.
* Specifically, set {@code this.items} to the {@code NgModelCtrl#$viewVale}.
Expand Down
4 changes: 2 additions & 2 deletions src/components/chips/js/chipsDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<div class="md-chip-content"\
ng-click="!$mdChipsCtrl.readonly && $mdChipsCtrl.selectChip($index)"\
md-chip-transclude="$mdChipsCtrl.chipContentsTemplate"></div>\
<div class="md-chip-remove-container" \
<div class="md-chip-remove-container"\
md-chip-transclude="$mdChipsCtrl.chipRemoveTemplate"></div>\
</md-chip>\
<div ng-if="!$mdChipsCtrl.readonly && $mdChipsCtrl.ngModelCtrl"\
Expand All @@ -126,7 +126,7 @@
<button\
class="md-chip-remove"\
ng-if="!$mdChipsCtrl.readonly"\
ng-click="$mdChipsCtrl.removeChip($index)"\
ng-click="$mdChipsCtrl.removeChip($$replacedScope.$index)"\
tabindex="-1">\
<md-icon md-svg-icon="close"></md-icon>\
<span class="md-visually-hidden">\
Expand Down

0 comments on commit 59d359c

Please sign in to comment.