Skip to content

docs: fix layout shift when refreshing the stagger example#69634

Open
erkamyaman wants to merge 1 commit into
angular:mainfrom
erkamyaman:docs-animations-stagger-refresh-layout-shift
Open

docs: fix layout shift when refreshing the stagger example#69634
erkamyaman wants to merge 1 commit into
angular:mainfrom
erkamyaman:docs-animations-stagger-refresh-layout-shift

Conversation

@erkamyaman

Copy link
Copy Markdown
Contributor

Clicking "Refresh" toggles the list out of and back into the DOM, but the <ul> lived inside the @if, so removing it collapsed the layout and caused a vertical jump. Wrap the list in a fixed-height .items-container to reserve the space while it re-mounts. Also key the stagger delay off $index so the first item animates immediately instead of being delayed a step.

PR Checklist

Please check that your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other

What is the current behavior?

In the native-css "Stagger" animations example, clicking Refresh makes the whole box shrink and snap back, with the list jumping up and then down. This happens because the <ul> sits inside the @if, so replaying the animation removes it from the layout and collapses the container to zero height. The first item is also delayed one full step before it animates in, because the stagger delay is keyed off the item value instead of its position.

Screen.Recording.2026-07-03.at.17.46.31.mov

What is the new behavior?

The list is wrapped in a fixed-height .items-container (matching the wrapper convention used by the neighboring insert/remove/open-close examples), so the space is held while the list re-mounts and there is no layout jump. The stagger delay is keyed off $index, so the first item animates immediately and the cascade no longer depends on the item values.

Screen.Recording.2026-07-03.at.17.46.57.mov

Does this PR introduce a breaking change?

  • Yes
  • No

@angular-robot angular-robot Bot added the area: docs Related to the documentation label Jul 3, 2026
@ngbot ngbot Bot added this to the Backlog milestone Jul 3, 2026
@erkamyaman erkamyaman marked this pull request as ready for review July 3, 2026 14:52
@pullapprove pullapprove Bot requested a review from josephperrott July 3, 2026 14:52
@erkamyaman

Copy link
Copy Markdown
Contributor Author

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Deployed adev-preview for c2ab6b9 to: https://ng-dev-previews-fw--pr-angular-angular-69634-adev-prev-4mfelrzq.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

Comment thread adev/src/content/examples/animations/src/app/native-css/stagger.html Outdated
Clicking "Refresh" toggles the list out of and back into the DOM, but the
`<ul>` lived inside the `@if`, so removing it collapsed the layout and
caused a vertical jump. Wrap the list in a fixed-height `.items-container`
to reserve the space while it re-mounts. Also key the stagger delay off
`$index` so the first item animates immediately instead of being delayed a
step.
@erkamyaman erkamyaman force-pushed the docs-animations-stagger-refresh-layout-shift branch from c2ab6b9 to 6369783 Compare July 3, 2026 15:23
@erkamyaman erkamyaman requested a review from JeanMeche July 3, 2026 15:24
@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jul 3, 2026
@JeanMeche JeanMeche removed the request for review from josephperrott July 3, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker adev: preview area: docs Related to the documentation target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants