-
Notifications
You must be signed in to change notification settings - Fork 3.4k
chips: editable mdChip not working properly #10879
Description
Issue:
I found out that the editable functionality of md-chip is not working properly. Every time I try to edit the value of a chip it'll disappear.
Steps to reproduce the issue:
- Go to the "Make chips editable." section of site: https://material.angularjs.org/latest/demo/chips
- Then type fruit name in text box.
- Navigate to any chip using left and right arrow.
- press space to make it editable
- type new value or change the existing one
- press enter the newly created chip will disappear.
Additional Information:
Browser Type: Chrome*
Browser Version: 60.03*
OS: Windows 10*
What I found is the problem is with this piece of code in angular-material.js at line number 26743.
MdChipCtrl.prototype.getContentElement = function() { return angular.element(
this.getChipContent().children()[0]); };
this.getChipContent().children()
becomes empty, and doesn't return the first child element which is text label that contains the user inputted value as a result var content = this.getContentElement().text();
at line number 26766 returns empty string.
MdChipCtrl.prototype.goOutOfEditMode = function() {
if (!this.isEditting) return;
this.isEditting = false;
this.$element.removeClass('_md-chip-editing');
this.getChipContent()[0].contentEditable = 'false';
var chipIndex = this.getChipIndex();
var content = this.getContentElement().text();
if (content) {
this.parentController.updateChipContents(
chipIndex,
this.getContentElement().text()
);
this.$mdUtil.nextTick(function() {
if (this.parentController.selectedChip === chipIndex) {
this.parentController.focusChip(chipIndex);
}
}.bind(this));
} else {
**//THIS CODE EXECUTES RESULTING IN DELETION OF CHIP FROM THE MODEL**
this.parentController.removeChipAndFocusInput(chipIndex);
}
};
Solution:
MdChipCtrl.prototype.getContentElement = function() { return angular.element(this.getChipContent().first); };*