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

fix(material/expansion-panel): Prevent focus issue during collapse animation #27684

Conversation

kharazian
Copy link
Contributor

@kharazian kharazian commented Aug 19, 2023

This commit addresses an issue where mat-expansion-panels were breaking when a user attempted to quickly close and tab away from a panel after closing it. The issue occurred because the tab key was being pressed between the collapsing animation, causing the panel body to remain visible and receive focus.

To resolve this, we manually set the panel's visibility to hidden when the tab key is pressed during the collapsing animation. This ensures that the next element in the tab order receives focus as expected.

Fix #27430

default:
if (this.panel.accordion) {
this.panel.accordion._handleHeaderKeydown(event);
case TAB:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that preventing users from tabbing is the right way to solve this issue. E.g. one could trigger it by clicking quickly as well. Instead we should not allow the panel to be toggled while an animation is running.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary issue is that when a panel collapses, we expect the focus to smoothly transition to the next element when we press the tab key. However, if someone quickly presses the tab key during the collapse animation, the body panel isn't hidden fast enough, leading to an incorrect focus allocation, which causes some problems.

the collapse animation state:

state('collapsed, void', style({height: '0px', visibility: 'hidden'})),)

To address this, we can implement a solution where the panel animation happens rapidly while it's in the middle of collapsing when using the tab key. This adjustment ensures that the focus behaves correctly. If you have further thoughts, please feel free to share them.

@kharazian kharazian requested a review from crisbeto September 12, 2023 19:45
This commit addresses an issue where mat-expansion-panels were breaking when a user attempted
to quickly close and tab away from a panel after closing it. The issue occurred because the tab
key was being pressed between the collapsing animation, causing the panel body to remain visible
and receive focus.

To resolve this, we manually set the panel's visibility to hidden when the tab key is pressed
during the collapsing animation. This ensures that the next element in the tab order receives
focus as expected.

Fixes angular#27430.
@kharazian kharazian force-pushed the fix-rapid-tab-press-during-collapse-animation branch from 8a302e3 to 3d1cfd4 Compare September 27, 2023 13:04
@crisbeto
Copy link
Member

Closing in favor of #28646.

@crisbeto crisbeto closed this Feb 26, 2024
@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 Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(expansion): expansion panel breaks when quickly closing panels using keyboard commands
2 participants