Add slClear event to input

This commit is contained in:
Cory LaViska
2020-08-25 16:24:33 -04:00
parent de1daad04e
commit e169c937df

View File

@@ -118,6 +118,9 @@ export class Input {
/** Emitted when the control's value changes. */
@Event() slChange: EventEmitter;
/** Emitted when the clear button is activated. */
@Event() slClear: EventEmitter;
/** Emitted when the control receives input. */
@Event() slInput: EventEmitter;
@@ -196,13 +199,15 @@ export class Input {
this.slFocus.emit();
}
handleClearClick() {
handleClearClick(event: MouseEvent) {
if (this.input.value !== '') {
this.input.value = '';
this.input.dispatchEvent(new window.Event('input', { bubbles: true }));
this.input.dispatchEvent(new window.Event('change', { bubbles: true }));
}
event.stopPropagation();
this.slClear.emit();
this.input.focus();
}