Skip to content

Commit 7d586e4

Browse files
devversionjelbourn
authored andcommitted
fix(input): do not focus input element twice (#12851)
* Currently if a user clicks on a input, the element receives focus and the `click` event bubbles up. Once it reaches the `<mat-form-field>`, the click event will cause the `onContainerClick` method to be invoked. This method then manually focused the input element (again). Resulting in unexpected behavior for time inputs in Firefox. Fixes #12849
1 parent 3e22641 commit 7d586e4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib/input/input.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,5 +392,12 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
392392
* Implemented as part of MatFormFieldControl.
393393
* @docs-private
394394
*/
395-
onContainerClick() { this.focus(); }
395+
onContainerClick() {
396+
// Do not re-focus the input element if the element is already focused. Otherwise it can happen
397+
// that someone clicks on a time input and the cursor resets to the "hours" field while the
398+
// "minutes" field was actually clicked. See: https://github.com/angular/material2/issues/12849
399+
if (!this.focused) {
400+
this.focus();
401+
}
402+
}
396403
}

0 commit comments

Comments
 (0)