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(cdk/scrolling): fix scrolling in appendOnly mode #24153

Merged
merged 1 commit into from
Feb 7, 2022

Conversation

chabb
Copy link
Contributor

@chabb chabb commented Jan 3, 2022

Hi,

This fixes #23577

The rendered content offset is incorrectly set in appendOnly; it should not change. This causes a weird behavior where the list jumps to the top

CC: @MichaelJamesParsons as you added the appendOnly flag in 8f052cc,, and @mmalerba as ( I think ) your are the main author for the virtual-scrolling

@crisbeto crisbeto requested a review from mmalerba January 3, 2022 10:14
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Jan 3, 2022
@@ -174,7 +174,8 @@ export class FixedSizeVirtualScrollStrategy implements VirtualScrollStrategy {
}

this._viewport.setRenderedRange(newRange);
this._viewport.setRenderedContentOffset(this._itemSize * newRange.start);
const newRangeStart = this._viewport.getRenderedRange().start * this._itemSize;
Copy link
Contributor

Choose a reason for hiding this comment

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

This change doesn't seem quite right to me. I notice that setRenderedRange is special-cased for append only mode, I think setRenderedContentOffset may need something similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get the point, it's the responsability of the viewport to do this logic, otherwise it would be in all classes implementing VirtualScrollStrategy

@chabb chabb force-pushed the fix-fixed-virtual-scroll branch 3 times, most recently from 8c95608 to 25d455d Compare January 5, 2022 07:34
@@ -321,6 +321,8 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
const axis = isHorizontal ? 'X' : 'Y';
const axisDirection = isHorizontal && isRtl ? -1 : 1;
let transform = `translate${axis}(${Number(axisDirection * offset)}px)`;
// in appendOnly, we always start from the top
Copy link
Contributor Author

@chabb chabb Jan 5, 2022

Choose a reason for hiding this comment

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

@mmalerba I've moved the logic to the virtual-scroll-viewport and added two tests.
I'm wondering if we need to update the offset when to is set to to-end. I've added a unit test for this case and the offset is correctly set. I think it's because we are recalculating the values with 'to-start' afterward.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good, thanks!

The rendered content offset is incorrectly set in appendOnly.
It should be set to 0.
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Feb 4, 2022
@zarend zarend merged commit 5221b79 into angular:master Feb 7, 2022
zarend pushed a commit that referenced this pull request Feb 7, 2022
The rendered content offset is incorrectly set in appendOnly.
It should be set to 0.

(cherry picked from commit 5221b79)
@philippspindler
Copy link

Thanks for taking care and fixing my raised issue!

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Feb 15, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/cdk](https://github.com/angular/components) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fcdk/13.2.1/13.2.2) |
| [@angular/material](https://github.com/angular/components) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fmaterial/13.2.1/13.2.2) |

---

### Release Notes

<details>
<summary>angular/components</summary>

### [`v13.2.2`](https://github.com/angular/components/blob/HEAD/CHANGELOG.md#&#8203;1322-enamel-eagle-2022-02-09)

[Compare Source](angular/components@13.2.1...13.2.2)

##### cdk

| Commit | Type | Description |
| -- | -- | -- |
| [4b6e83274](angular/components@4b6e832) | fix | **scrolling:** fix scrolling in appendOnly mode ([#&#8203;24153](angular/components#24153)) |

##### material

| Commit | Type | Description |
| -- | -- | -- |
| [f5199eeeb](angular/components@f5199ee) | fix | **datepicker:** fix improper focus trapping with VoiceOver and ChromeVox ([#&#8203;24300](angular/components#24300)) |
| [a72bcbe50](angular/components@a72bcbe) | fix | **datepicker:** remove abbr from day of week header ([#&#8203;24106](angular/components#24106)) |

##### material-experimental

| Commit | Type | Description |
| -- | -- | -- |
| [3bbcb444f](angular/components@3bbcb44) | fix | **mdc-checkbox:** add missing classes for checked ([#&#8203;24350](angular/components#24350)) |

##### material-experiental

| Commit | Type | Description |
| -- | -- | -- |
| [70bec6054](angular/components@70bec60) | fix | **mdc-list:** update material-components-web to pick up multi-select list keyboard support ([#&#8203;24354](angular/components#24354)) |

#### Special Thanks

Alan Agius, Artur Androsovych, Chabbey François, Joey Perrott, Kristiyan Kostadinov, Miles Malerba, Paul Gschwendtner, Zach Arend and renovate\[bot]

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1161
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
amysorto pushed a commit to amysorto/components that referenced this pull request Feb 15, 2022
The rendered content offset is incorrectly set in appendOnly.
It should be set to 0.
@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 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(cdk/scrolling): Append only mode together with FixedSizeVirtualScrollStrategy results in a jumping view
5 participants