(ev: KeyboardEvent)
| 602 | }; |
| 603 | |
| 604 | private checkClearOnEdit(ev: KeyboardEvent) { |
| 605 | if (!this.shouldClearOnEdit()) { |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * The following keys do not modify the |
| 611 | * contents of the input. As a result, pressing |
| 612 | * them should not edit the input. |
| 613 | * |
| 614 | * We can't check to see if the value of the input |
| 615 | * was changed because we call checkClearOnEdit |
| 616 | * in a keydown listener, and the key has not yet |
| 617 | * been added to the input. |
| 618 | */ |
| 619 | const IGNORED_KEYS = ['Enter', 'Tab', 'Shift', 'Meta', 'Alt', 'Control']; |
| 620 | const pressedIgnoredKey = IGNORED_KEYS.includes(ev.key); |
| 621 | |
| 622 | /** |
| 623 | * Clear the input if the control has not been previously cleared during focus. |
| 624 | * Do not clear if the user hitting enter to submit a form. |
| 625 | */ |
| 626 | if (!this.didInputClearOnEdit && this.hasValue() && !pressedIgnoredKey) { |
| 627 | this.value = ''; |
| 628 | this.emitInputChange(ev); |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Pressing an IGNORED_KEYS first and |
| 633 | * then an allowed key will cause the input to not |
| 634 | * be cleared. |
| 635 | */ |
| 636 | if (!pressedIgnoredKey) { |
| 637 | this.didInputClearOnEdit = true; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | private onCompositionStart = () => { |
| 642 | this.isComposing = true; |
no test coverage detected