fix(material/stepper): incorrect navigation order when steps are added later on #23541
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.
The Material stepper's template is set up such that we have a single
ng-template
at the bottom declaring the header which is then rendered out with anngTemplateOutlet
inside anngFor
. We do this in order to reduce duplication, because a lot of properties and attributes have to be set onmat-step-header
.Then problem with this approach is that because the header is outside the
ngFor
, it may not appear in the correct order in thengFor
if the list changes. This results in incorrect navigation order when using the next/previous buttons or the keyboard.These changes add some logic that will sort the headers based on their position in the DOM in order to work around the issue. Alternatively, we could fix this by inlining the
mat-step-header
template, but that'll result in some duplicated code that is somewhat error-prone if we ever need to add more attributes.Fixes #23539.