2017-06-21 5 views
0

Nach der Aktualisierung der Angular Material von Version 1.1.1 zu 1.1.4, die MD-Chips funktionieren nicht wie zuvor.Re-Fokus nach Klick außerhalb MD-Chips

Geben Sie eine Zeichenfolge in den Eintrag ein und klicken Sie dann außerhalb, der Fokus kehrt zur Eingabe zurück.

Ich möchte nicht, dass dies geschieht.

Mit scharfkantigem Material 1.1.1:

https://youtu.be/LD2CxbuMxJg

Mit scharfkantigem Material 1.1.4:

https://youtu.be/dG1kKvU1Y0s

Kann jemand mir bitte helfen?

+0

ich nicht in der Lage bin, dies wieder herzustellen. Welchen Browser benutzen Sie? –

+0

Live-Beispiel von [Angular Material 1.1.4] (https://fiddle.jshell.net/nxvp1mdu/3/) und [Angular Material 1.1.1] (https://fiddle.jshell.net/c1osj4p7/2/) –

Antwort

0

In mdChipsCtrl gibt es eine boolesche Variable, die dafür verantwortlich ist, den Fokus auf den Eintrag shouldFocusLastChip zurückzusetzen.

ich überschrieben die Funktion, indem Sie den Wert dieser Variablen mit der folgenden Richtlinie zu ändern:

angular.module('myApp').directive('mdChips', function() { 
    return {                 
    restrict: 'E',               
    require: 'mdChips', // Extends the original mdChips directive   
    link: function (scope, element, attributes, mdChipsCtrl) {    
     mdChipsCtrl.appendChip = function (newChip) { 
     // Set to FALSE         
     this.shouldFocusLastChip = false;                  

     if (this.useTransformChip && this.transformChip) {     
      var transformedChip = this.transformChip({'$chip': newChip});  

      // Check to make sure the chip is defined before assigning it, otherwise, we'll just assume 
      // they want the string version.         
      if (angular.isDefined(transformedChip)) {       
      newChip = transformedChip;          
      }                 
     }                 

     // If items contains an identical object to newChip, do not append 
     if (angular.isObject(newChip)){          
      var identical = this.items.some(function(item){     
      return angular.equals(newChip, item);       
      });                
      if (identical) return;            
     }                 

     // Check for a null (but not undefined), or existing chip and cancel appending 
     if (newChip === null || this.items.indexOf(newChip) + 1) return;  

     // Append the new chip onto our list         
     var length = this.items.push(newChip);        
     var index = length - 1;            

     // Update model validation           
     this.ngModelCtrl.$setDirty();          
     this.validateModel();            

     // If they provide the md-on-add attribute, notify them of the chip addition 
     if (this.useOnAdd && this.onAdd) {         
      this.onAdd({ '$chip': newChip, '$index': index });     
     }                 
     };                  
    }                  
};