Callback for the cases where the focused state of the input changes.
(isFocused: boolean)
| 422 | |
| 423 | /** Callback for the cases where the focused state of the input changes. */ |
| 424 | _focusChanged(isFocused: boolean) { |
| 425 | if (isFocused === this.focused) { |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | if (!this._isNativeSelect && isFocused && this.disabled && this.disabledInteractive) { |
| 430 | const element = this._elementRef.nativeElement as HTMLInputElement; |
| 431 | |
| 432 | // Focusing an input that has text will cause all the text to be selected. Clear it since |
| 433 | // the user won't be able to change it. This is based on the internal implementation. |
| 434 | if (element.type === 'number') { |
| 435 | // setSelectionRange doesn't work on number inputs so it needs to be set briefly to text. |
| 436 | element.type = 'text'; |
| 437 | element.setSelectionRange(0, 0); |
| 438 | element.type = 'number'; |
| 439 | } else { |
| 440 | element.setSelectionRange(0, 0); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | this.focused = isFocused; |
| 445 | this.stateChanges.next(); |
| 446 | } |
| 447 | |
| 448 | _onInput() { |
| 449 | // This is a noop function and is used to let Angular know whenever the value changes. |