fix(angular): remove the tabindex set by routerLink from Ionic components #29742
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue number: resolves #20632
What is the current behavior?
When using the
routerLink
directive in Angular, it automatically addstabindex="0"
to the element. This creates issues with Ionic components that render native button or anchor elements, as they have their own focus management. As a result, when navigating between list items withrouterLink
using theTab
key, you need to press theTab
key twice to move to the next item. This problem is illustrated in the following demo:Related Angular issue: angular/angular#28345
What is the new behavior?
Updated our
RouterLinkDelegateDirective
to check if the element usingrouterLink
is one of the following Ionic components:ion-back-button
,ion-breadcrumb
,ion-button
,ion-card
,ion-fab-button
,ion-item
,ion-item-option
,ion-menu-button
,ion-segment-button
, orion-tab-button
. If so, it removes thetabindex
attribute from the element. This allows these Ionic components to let the native button or anchor element handle the focus.This solution is demonstrated in the following demo:
Note
I did not include the
ion-router-link
component in the list to removetabindex
because the router link documentation does not recommend using it with Angular:Does this introduce a breaking change?
Other information
Dev build:
8.2.7-dev.11722448707.1e8c66e6