matcha-components 20.123.0 → 20.125.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11591,34 +11591,72 @@ class MatchaAutocompleteTriggerDirective {
11591
11591
  console.log('MatchaAutocomplete: writeValueToInput chamado', {
11592
11592
  displayText,
11593
11593
  actualValue,
11594
- input: this.el.nativeElement
11594
+ input: this.el.nativeElement,
11595
+ hasNgControl: !!this.ngControl
11595
11596
  });
11596
11597
  const input = this.el.nativeElement;
11597
- input.value = displayText == null ? '' : String(displayText);
11598
- // Dispatch múltiplos eventos para garantir compatibilidade com Angular Forms
11599
- const inputEvent = new Event('input', { bubbles: true });
11600
- const changeEvent = new Event('change', { bubbles: true });
11601
- input.dispatchEvent(inputEvent);
11602
- input.dispatchEvent(changeEvent);
11598
+ // Se ngControl e actualValue é um objeto (não string), atualizar FormControl diretamente
11599
+ if (this.ngControl && this.ngControl.control && actualValue !== undefined) {
11600
+ // Se actualValue é um objeto, atualizar o FormControl com o objeto completo
11601
+ if (typeof actualValue === 'object' && actualValue !== null) {
11602
+ console.log('MatchaAutocomplete: Atualizando FormControl com objeto', actualValue);
11603
+ // Usar setValue com emitEvent: false para evitar loop infinito, depois emitir manualmente
11604
+ this.ngControl.control.setValue(actualValue, { emitEvent: false });
11605
+ // Atualizar o input visual com o displayText
11606
+ input.value = displayText == null ? '' : String(displayText);
11607
+ // Emitir eventos de mudança manualmente
11608
+ this.ngControl.control.updateValueAndValidity({ emitEvent: true });
11609
+ }
11610
+ else {
11611
+ // Se actualValue é primitivo, atualizar normalmente
11612
+ input.value = displayText == null ? '' : String(displayText);
11613
+ // Dispatch eventos para garantir compatibilidade com Angular Forms
11614
+ const inputEvent = new Event('input', { bubbles: true });
11615
+ const changeEvent = new Event('change', { bubbles: true });
11616
+ input.dispatchEvent(inputEvent);
11617
+ input.dispatchEvent(changeEvent);
11618
+ }
11619
+ }
11620
+ else {
11621
+ // Sem ngControl ou sem actualValue, apenas atualizar o input visual
11622
+ input.value = displayText == null ? '' : String(displayText);
11623
+ // Dispatch eventos para garantir compatibilidade com Angular Forms
11624
+ const inputEvent = new Event('input', { bubbles: true });
11625
+ const changeEvent = new Event('change', { bubbles: true });
11626
+ input.dispatchEvent(inputEvent);
11627
+ input.dispatchEvent(changeEvent);
11628
+ }
11603
11629
  // Atualizar visibilidade do botão após escrever valor
11604
11630
  setTimeout(() => {
11605
11631
  this.updateClearButtonVisibility();
11606
11632
  }, 0);
11607
- console.log('MatchaAutocomplete: Valor escrito no input', input.value);
11633
+ console.log('MatchaAutocomplete: Valor escrito no input', {
11634
+ inputValue: input.value,
11635
+ formControlValue: this.ngControl?.control?.value
11636
+ });
11608
11637
  }
11609
11638
  clearInput() {
11610
11639
  const input = this.el.nativeElement;
11611
11640
  input.value = '';
11612
- // Dispatch eventos para garantir compatibilidade com Angular Forms
11613
- const inputEvent = new Event('input', { bubbles: true });
11614
- const changeEvent = new Event('change', { bubbles: true });
11615
- const blurEvent = new Event('blur', { bubbles: true });
11616
- input.dispatchEvent(inputEvent);
11617
- input.dispatchEvent(changeEvent);
11618
- input.dispatchEvent(blurEvent);
11641
+ // Se ngControl, limpar o FormControl diretamente
11642
+ if (this.ngControl && this.ngControl.control) {
11643
+ console.log('MatchaAutocomplete: Limpando FormControl');
11644
+ this.ngControl.control.setValue(null, { emitEvent: true });
11645
+ }
11646
+ else {
11647
+ // Sem ngControl, apenas disparar eventos
11648
+ const inputEvent = new Event('input', { bubbles: true });
11649
+ const changeEvent = new Event('change', { bubbles: true });
11650
+ const blurEvent = new Event('blur', { bubbles: true });
11651
+ input.dispatchEvent(inputEvent);
11652
+ input.dispatchEvent(changeEvent);
11653
+ input.dispatchEvent(blurEvent);
11654
+ }
11619
11655
  // Atualizar visibilidade do botão
11620
11656
  this.updateClearButtonVisibility();
11621
- console.log('MatchaAutocomplete: Input limpo');
11657
+ console.log('MatchaAutocomplete: Input limpo', {
11658
+ formControlValue: this.ngControl?.control?.value
11659
+ });
11622
11660
  }
11623
11661
  onClick() {
11624
11662
  // Abrir painel quando clicar no input
@@ -11875,10 +11913,7 @@ class MatchaAutocompleteModule {
11875
11913
  MatchaAutocompleteTriggerDirective,
11876
11914
  MatchaOptionModule // Re-exporta para conveniência
11877
11915
  ] }); }
11878
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: MatchaAutocompleteModule, providers: [
11879
- // Provider para permitir injeção da interface MatchaOptionParent
11880
- { provide: MATCHA_OPTION_PARENT, useExisting: MatchaAutocompleteComponent }
11881
- ], imports: [CommonModule,
11916
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: MatchaAutocompleteModule, imports: [CommonModule,
11882
11917
  MatchaOptionModule,
11883
11918
  MatchaPanelModule, MatchaOptionModule // Re-exporta para conveniência
11884
11919
  ] }); }
@@ -11899,10 +11934,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImpor
11899
11934
  MatchaAutocompleteComponent,
11900
11935
  MatchaAutocompleteTriggerDirective,
11901
11936
  MatchaOptionModule // Re-exporta para conveniência
11902
- ],
11903
- providers: [
11904
- // Provider para permitir injeção da interface MatchaOptionParent
11905
- { provide: MATCHA_OPTION_PARENT, useExisting: MatchaAutocompleteComponent }
11906
11937
  ]
11907
11938
  }]
11908
11939
  }] });