Skip to content

Commit 13a4b5c

Browse files
authored
Merge pull request #23 from martinpetlus/fix-change-event-propagation
(fix) Stop the input change event propagation
2 parents a3cfba0 + 9644bed commit 13a4b5c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/typeahead.component.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'rxjs/add/operator/toArray';
1111
import 'rxjs/add/operator/filter';
1212
import 'rxjs/add/operator/mergeAll';
1313
import 'rxjs/add/operator/publishReplay';
14+
import 'rxjs/add/observable/of';
1415
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
1516
import { TypeaheadSettings, TypeaheadSuggestions } from './typeahead.interface';
1617

@@ -92,7 +93,8 @@ const sanitizeString = (text: string) =>
9293
(keyup)="handleInput($event)"
9394
(keydown)="handleInput($event)"
9495
(paste)="handleInput($event)"
95-
(click)="toggleDropdown(true)"/>
96+
(click)="toggleDropdown(true)"
97+
(change)="handleInputChange($event)">
9698
<i *ngIf="!isDisabled" (click)="toggleDropdown()" tabindex="-1"
9799
[ngClass]="settings.dropdownToggleClass"></i>
98100
<div role="menu" [attr.class]="dropDownClass" *ngIf="matches.length || !custom">
@@ -329,6 +331,16 @@ export class TypeaheadComponent implements ControlValueAccessor, AfterViewInit,
329331
this.writeValue(value);
330332
}
331333

334+
/**
335+
* Handle input change event
336+
* @param {Event} event
337+
*/
338+
handleInputChange(event: Event) {
339+
// Stop the propagation of event up the DOM tree in case
340+
// `change` event handler is attached to host component.
341+
event.stopPropagation();
342+
}
343+
332344
/**
333345
* Update value on input change
334346
* @param event

0 commit comments

Comments
 (0)