Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mat-datepicker with touchUI emits (closed) too soon? #17560

Closed
robert-king opened this issue Oct 31, 2019 · 2 comments · Fixed by #17732 or lingounet/testage#29
Closed

mat-datepicker with touchUI emits (closed) too soon? #17560

robert-king opened this issue Oct 31, 2019 · 2 comments · Fixed by #17732 or lingounet/testage#29
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@robert-king
Copy link

Reproduction

Steps to reproduce:
https://stackblitz.com/edit/components-issue-oa5rhf

<mat-form-field>
      <input
        matInput
        (focus)="picker.open()"
        required
        #input
        name="date"
        [matDatepicker]="picker"
        formControlName="serializedDate"
        placeholder="Working without blur">
      <mat-datepicker-toggle
        matSuffix
        [for]="picker">
      </mat-datepicker-toggle>
      <mat-datepicker
        [touchUi]="true"
        #picker>
      </mat-datepicker>
    </mat-form-field>

    <mat-form-field>
      <input
        matInput
        (focus)="picker2.open()"
        required
        #input2
        name="date"
        [matDatepicker]="picker2"
        formControlName="serializedDate"
        placeholder="Broken with blur">
      <mat-datepicker-toggle
        matSuffix
        [for]="picker2">
      </mat-datepicker-toggle>
      <mat-datepicker
        [touchUi]="true"
        (closed)="input2.blur()"
        #picker2>
      </mat-datepicker>
    </mat-form-field>

Expected Behavior

picker closes and then (close) emits and input.blur() is called

Actual Behavior

close emits and blur is called before the other (focus) is called?
The screen flashes in a loop and is frozen / unresponsive

Environment

see stackblitz - everything is the latest as of today AFAIK

Note: I do have a fix for this already, if i set a BIG timeout on the input.blur() of 150 MS, then it doesn't happen.

delayInputBlur(input: HTMLElement) {
    setTimeout(() => input.blur(), 150);
  }
@crisbeto crisbeto self-assigned this Nov 17, 2019
@crisbeto crisbeto added has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Nov 17, 2019
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 17, 2019
`MatDatepicker` has focus restoration which happens (almost) synchronously, whereas `MatDialog` restores focus asynchronously when the animation is finished. This means that in `touchUi` mode focus ends up being restored both by the datepicker and the dialog within a 150ms window. The problem is that if the consumer of `MatDatepicker` decides to move focus inside the `closed` event, it'll be ovewritten by the dialog 150ms later. These changes disable the dialog's focus restoration because it's unnecessary.

Fixes angular#17560.
@crisbeto
Copy link
Member

Will be fixed by #17732. Until then your workaround with the timeout should work.

crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 6, 2020
`MatDatepicker` has focus restoration which happens (almost) synchronously, whereas `MatDialog` restores focus asynchronously when the animation is finished. This means that in `touchUi` mode focus ends up being restored both by the datepicker and the dialog within a 150ms window. The problem is that if the consumer of `MatDatepicker` decides to move focus inside the `closed` event, it'll be ovewritten by the dialog 150ms later. These changes disable the dialog's focus restoration because it's unnecessary.

Fixes angular#17560.
jelbourn pushed a commit that referenced this issue Apr 23, 2020
#17732)

`MatDatepicker` has focus restoration which happens (almost) synchronously, whereas `MatDialog` restores focus asynchronously when the animation is finished. This means that in `touchUi` mode focus ends up being restored both by the datepicker and the dialog within a 150ms window. The problem is that if the consumer of `MatDatepicker` decides to move focus inside the `closed` event, it'll be ovewritten by the dialog 150ms later. These changes disable the dialog's focus restoration because it's unnecessary.

Fixes #17560.
jelbourn pushed a commit that referenced this issue Apr 23, 2020
#17732)

`MatDatepicker` has focus restoration which happens (almost) synchronously, whereas `MatDialog` restores focus asynchronously when the animation is finished. This means that in `touchUi` mode focus ends up being restored both by the datepicker and the dialog within a 150ms window. The problem is that if the consumer of `MatDatepicker` decides to move focus inside the `closed` event, it'll be ovewritten by the dialog 150ms later. These changes disable the dialog's focus restoration because it's unnecessary.

Fixes #17560.
soro-google pushed a commit to soro-google/components that referenced this issue Apr 24, 2020
angular#17732)

`MatDatepicker` has focus restoration which happens (almost) synchronously, whereas `MatDialog` restores focus asynchronously when the animation is finished. This means that in `touchUi` mode focus ends up being restored both by the datepicker and the dialog within a 150ms window. The problem is that if the consumer of `MatDatepicker` decides to move focus inside the `closed` event, it'll be ovewritten by the dialog 150ms later. These changes disable the dialog's focus restoration because it's unnecessary.

Fixes angular#17560.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
2 participants