-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
bug(MatDialog): When opening multiple dialogs in a short amount of time, some of them do not open #24037
Comments
We encounter the same issue, If we call open in ngOnInit like below:
The dialog dose not open anymore, it is fine in previous version. However, if we just:
The dialog will be opened correctly. |
We've also hit this issue. I'm sure it was introduced with this commit. There's a comment on it that points to the underlying issue. The commit message says the goal is to [a]void opening multiple of the same dialog before animations complete by returning the previous // injected in real code
declare const dialog: MatDialog;
// somewhere in the codebase
const dialogA = dialog.open(DialogA); // dialog that shows a spinner while async thing A is happening
// somewhere else in codebase, gets executed as part of A succeeding but can fail independently
const dialogB = dialog.open(DialogB); // dialog that shows an error
dialogB.afterClosed().pipe(/* do stuff according to user response */); The way the timing works out in our case, Any chance you could take another look at this, @Splaktar? |
Thank you for the example code. It would be great if you could provide a runnable StackBlitz to help us investigate this more efficiently. |
- notify screen reader users that they have entered a dialog - previously only the focused element would be read i.e. "Close Button Press Search plus Space to activate" - now the screen reader user gets the normal dialog behavior, which is to read the dialog title, role, content, and then tell the user about the focused element - this matches the guidance here: https://www.w3.org/TR/wai-aria-practices-1.1/examples/dialog-modal/dialog.html - Avoid opening multiple of the same dialog before animations complete by returning the previous `MatDialogRef` - update material/dialog API golden file Fixes #21840
Does this still happen when you import components/src/material/dialog/dialog.ts Lines 467 to 468 in 0b02322
|
@lephyrus there is a lot of discussion about the tradeoffs and issues that we faced here in the following PRs |
If I had a StackBlitz for this, I could try out a few quick things right now and see if I can provide a workaround, but since I don't, I probably won't have time to look into this again this week. |
@Splaktar |
Doh. Thank you for linking that StackBlitz issue. Let me see if I can get you a working Angular v13 StackBlitz template. |
PR #13466 could potentially help, so you could disable the animation or at least know how long they would run in these cases. However, it's not clear if or when that will land. |
@Splaktar Can you provide an option to disable this behavior?, this impacts our product so much, many dialogs does not open correctly after upgrade the version. Thanks! |
I've could make a stackblitz example, it can be forked. |
My case is very similar to @lephyrus 's: |
Thanks, @Splaktar. Here's what I'm not clear on: The current behaviour is that no dialog will be opened while another one is opening. Is that the intention of the change? In the PR discussion, there is talk of components/src/material-experimental/mdc-dialog/dialog.spec.ts Lines 2010 to 2012 in 699e19b
Currently, this would pass but seems very strange (i.e. the reference I get from fooRef = dialog.open(Foo);
barRef = dialog.open(Bar);
expect(barRef).toEqual(fooRef);
expect(barRef.componentInstance instanceof Foo).toBe(true); |
adding a delay as @guimabdo says works as workarround |
FYI, StackBlitz now supports Angular 13. You can go ahead and make your repro if still needed.
Related StackBlitz issue comment: stackblitz/core#1657 (comment) |
Yes.
Yes, per code review feedback and due to breaking existing tests we moved away from that.
I think that part of the commit message just didn't get updated before the final merge of the PR. Sorry about that. This does cover the most common case we were focused on though, which was multiple clicks/key presses on a button (or other trigger) causing the dialog to be opened twice.
Wouldn't that trigger a TypeScript compiler error? |
Also on the topic of opening multiple dialogs at the same time, the Material Design guidelines for Dialogs include this description:
There are a number of other recommendations there that clearly call out something like "dialog that shows a spinner while async thing A is happening" as an improper use of a dialog. In those cases, you may want to look at building a custom component for your application using CDK Overlay which provides a number of position and scroll strategies. In #6761 (comment), @crisbeto mentioned that we officially support opening multiple dialogs on the page. It's not clear if he was intending to say that we support opening multiple dialogs in a very short period of time (before they can animate open). That said, I believe that the fix there is what caused the a11y issue in #21840 that I just fixed. |
We're facing the same issue in our application since Angular 13. Rolled back to version 12.x. This is a breaking change! If this is the intended behaviour we've to do a very large refactoring just to update to version 13 again. Very bad. |
@marsc can you please share your use case and a reproduction? |
@Kademlia in this case you can do something like this:
|
@marsc there lies the problem. If the task from the first dialog finishes before the first dialog is fully opened, the second dialog won't show up. |
PR #24121 has been tested and reviewed. It should land shortly and fix this. |
Any ETA? This is the only thing that is blocking the upgrade of my project. |
@aikrez there is nothing blocking the PR from being merged. It's been fully reviewed and approved. I can't give an ETA though. |
@aikrez okay, I do have an update. There have been some undesirable side effects of this change in the presubmit tests. They are being investigated and potential solutions and workarounds are being evaluated. |
This comment was marked as abuse.
This comment was marked as abuse.
Any updates? |
Would like to know too when this PR is getting merged. We're having a lot of problems with this issue at the moment 😢 |
It seems like opening a dialog from within another dialog also fails if there happened to be an error shortly before (within the animation duration). I cannot listen on "dialogOpened" observable, as this only triggers once, but the error will trigger the dialogContainer.start animation again. |
For a long time we used to move focus into the dialog after the opening animation was finished, because it allowed for the content to settle in case something like an autocomplete needed to open. This approach has caused us accessibility issues in the past, because we've had to find ways to prevent the user from interacting with content behind the dialog while the opening animation is running. Initially we used to move focus to the dialog container before transferring it into the dialog, but that ended up interrupting the screen reader. In a later change we started returning the previous dialog ref if the same kind of dialog is opened while the animation is still running. The problem with this approach is that it doesn't allow for multiple dialog to be opened quickly (see angular#24037). These changes aim to address the root cause by moving focus immediately after the dialog content is attached. If this causes regressions with autocompletes inside dialogs, we now have APIs that allow users to customize the focus behavior. Fixes angular#24037.
I reworked the fix for this on Friday to make it easier to merge and got it passing all the internal checks. It'll be merged in on Monday and should be out in the next patch release. |
…24121) * fix(material/dialog): don't wait for animation before moving focus For a long time we used to move focus into the dialog after the opening animation was finished, because it allowed for the content to settle in case something like an autocomplete needed to open. This approach has caused us accessibility issues in the past, because we've had to find ways to prevent the user from interacting with content behind the dialog while the opening animation is running. Initially we used to move focus to the dialog container before transferring it into the dialog, but that ended up interrupting the screen reader. In a later change we started returning the previous dialog ref if the same kind of dialog is opened while the animation is still running. The problem with this approach is that it doesn't allow for multiple dialog to be opened quickly (see #24037). These changes aim to address the root cause by moving focus immediately after the dialog content is attached. If this causes regressions with autocompletes inside dialogs, we now have APIs that allow users to customize the focus behavior. Fixes #24037. * fixup! fix(material/dialog): don't wait for animation before moving focus (cherry picked from commit 92863cc)
…24121) * fix(material/dialog): don't wait for animation before moving focus For a long time we used to move focus into the dialog after the opening animation was finished, because it allowed for the content to settle in case something like an autocomplete needed to open. This approach has caused us accessibility issues in the past, because we've had to find ways to prevent the user from interacting with content behind the dialog while the opening animation is running. Initially we used to move focus to the dialog container before transferring it into the dialog, but that ended up interrupting the screen reader. In a later change we started returning the previous dialog ref if the same kind of dialog is opened while the animation is still running. The problem with this approach is that it doesn't allow for multiple dialog to be opened quickly (see #24037). These changes aim to address the root cause by moving focus immediately after the dialog content is attached. If this causes regressions with autocompletes inside dialogs, we now have APIs that allow users to customize the focus behavior. Fixes #24037. * fixup! fix(material/dialog): don't wait for animation before moving focus
Hello, thanks for this fix ! |
The fix will be in |
This fix is included in 13.2.6 and 14.0.0-next.6. |
We have updated our applications to the new patch and everything seems to work as intended. Thanks! |
…ngular#24121) * fix(material/dialog): don't wait for animation before moving focus For a long time we used to move focus into the dialog after the opening animation was finished, because it allowed for the content to settle in case something like an autocomplete needed to open. This approach has caused us accessibility issues in the past, because we've had to find ways to prevent the user from interacting with content behind the dialog while the opening animation is running. Initially we used to move focus to the dialog container before transferring it into the dialog, but that ended up interrupting the screen reader. In a later change we started returning the previous dialog ref if the same kind of dialog is opened while the animation is still running. The problem with this approach is that it doesn't allow for multiple dialog to be opened quickly (see angular#24037). These changes aim to address the root cause by moving focus immediately after the dialog content is attached. If this causes regressions with autocompletes inside dialogs, we now have APIs that allow users to customize the focus behavior. Fixes angular#24037. * fixup! fix(material/dialog): don't wait for animation before moving focus
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Is this a regression?
The previous version in which this bug was not present was
12.2.0
Description
When opening multiple dialogs in a short amount of time, some of them do not open
Reproduction
The bug can be noticed with the example below, when clicking the "Open Fast" button.
Expected Behavior
"Open fast" button should open 6 dialogs, just like the "Open slow" button.
Actual Behavior
The "Open fast" button opens only 2 dialogs.
On most attempts it opens (1) and (5), but in some cases (1) and (6) are open.
Environment
The text was updated successfully, but these errors were encountered: