Skip to content

MatInput - On Mobile devices pressing enter key should trigger blur and hide keyboard #18523

@naveedahmed1

Description

@naveedahmed1

Reproduction

On mobile devices we often have text fields for example in case of search bar, where we want the form to be submitted when user hits enter key or search button on keyboard. When using normal HTML input, pressing enter/search button automatically submits the form and hides the keyboard.

When using matInput, though pressing enter/search button does submit the form but it doesn't hides the keyboard.

<form [formGroup]="form" (ngSubmit)="search()">
              <mat-form-field class="mat-form-field-full-width">
                <input matInput formControlName="keywords" type="search" placeholder="Title">
              </mat-form-field>
</form>

Expected Behavior

When using matInput, pressing enter/search button should hide the keyboard.

Actual Behavior

The keyboard remains visible although the form is submitted.

Environment

  • Angular: 9.x
  • CDK/Material:9.x
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Android

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidIssues specific to Androidarea: material/inputneeds: clarificationThe issue does not contain enough information for the team to determine if it is a real bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions