{{ message }}
fix(router): stop adding tabindex to non-anchor elements with routerLink - #70573
Open
arturovt wants to merge 1 commit into
Open
fix(router): stop adding tabindex to non-anchor elements with routerLink#70573arturovt wants to merge 1 commit into
arturovt wants to merge 1 commit into
Conversation
Contributor
Author
arturovt
marked this pull request as ready for review
September 4, 2026 20:00
arturovt
force-pushed
the
fix/router_28345_no-auto-tabindex
branch
from
September 5, 2026 20:36
8e90c73 to
d5ff504
Compare
RouterLink automatically set `tabindex="0"` on any non-`<a>`/`<area>`
element it was applied to, with no way to opt out short of writing a
literal tabindex attribute in the template. It also made the element
focusable without making it keyboard-operable, since RouterLink only
listens for click events and never handled Enter/Space.
The behavior is now gated behind `ADD_TABINDEX_TO_NON_ANCHOR_ELEMENTS`,
which is `false` in the published package and kept `true` inside Google
(via a sync marker) while internal callers migrate off it. Because it is a
module-level `const`, bundlers fold it to `false` and drop the guarded
`setTabIndexIfNotOnNativeEl` body, so the published package carries none of
the tabindex logic.
To let the rest tree-shake with it:
- `Renderer2` is dropped. It was used only to write the tabindex
attribute; that write now goes straight to the host element.
- `@Attribute('tabindex')` is replaced with a `HostAttributeToken`
injected only inside the `ADD_TABINDEX_TO_NON_ANCHOR_ELEMENTS` branch of
the constructor, so it is removed by the same fold.
The `RouterLink` constructor now takes `(router, route, el,
locationStrategy?)`.
BREAKING CHANGE: RouterLink no longer adds `tabindex="0"` to non-anchor
elements (e.g. `<div routerLink>`, `<button routerLink>`) by default. If
you need such an element to be part of the tab order, add `tabindex="0"`
to it directly in the template.
Fixes angular#28345
arturovt
force-pushed
the
fix/router_28345_no-auto-tabindex
branch
from
September 5, 2026 20:52
d5ff504 to
858d62a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

RouterLink automatically set
tabindex="0"on any non-<a>/<area>element it was applied to, with no way to opt out short of writing a
literal tabindex attribute in the template. It also made the element
focusable without making it keyboard-operable, since RouterLink only
listens for click events and never handled Enter/Space.
The behavior is now gated behind
ADD_TABINDEX_TO_NON_ANCHOR_ELEMENTS,which is
falsein the published package and kepttrueinside Google(via a sync marker) while internal callers migrate off it. Because it is a
module-level
const, bundlers fold it tofalseand drop the guardedsetTabIndexIfNotOnNativeElbody, so the published package carries none ofthe tabindex logic.
To let the rest tree-shake with it:
Renderer2is dropped. It was used only to write the tabindexattribute; that write now goes straight to the host element.
@Attribute('tabindex')is replaced with aHostAttributeTokeninjected only inside the
ADD_TABINDEX_TO_NON_ANCHOR_ELEMENTSbranch ofthe constructor, so it is removed by the same fold.
The
RouterLinkconstructor now takes(router, route, el, locationStrategy?).BREAKING CHANGE: RouterLink no longer adds
tabindex="0"to non-anchorelements (e.g.
<div routerLink>,<button routerLink>) by default. Ifyou need such an element to be part of the tab order, add
tabindex="0"to it directly in the template.
Fixes #28345