Skip to content

Commit

Permalink
Do not scroll if fully visible in smart logic
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jan 27, 2024
1 parent 807ec33 commit f7da641
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/ui-components/src/components/windowedlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export abstract class WindowedListModel implements WindowedList.IModel {
0,
itemMetadata.offset - size + itemMetadata.size
);
// Current offset (+/- padding) is the top edge of the viewport.
const currentOffset = precomputed
? precomputed.currentOffset
: this._scrollOffset;
Expand All @@ -372,6 +373,8 @@ export abstract class WindowedListModel implements WindowedList.IModel {
const crossingBottomEdge = bottomEdge > itemTop && bottomEdge < itemBottom;
const crossingTopEdge = topEdge > itemTop && topEdge < itemBottom;

const isFullyWithinViewport = bottomEdge > itemBottom && topEdge < itemTop;

if (align === 'smart') {
const edgeLessThanOneViewportAway =
currentOffset >= bottomOffset - size &&
Expand All @@ -381,6 +384,7 @@ export abstract class WindowedListModel implements WindowedList.IModel {
const hiddenPartTop = topEdge - itemTop;

if (
isFullyWithinViewport ||
(crossingBottomEdge && visiblePartBottom >= scrollDownThreshold) ||
(crossingTopEdge && hiddenPartTop < scrollUpThreshold)
) {
Expand All @@ -401,7 +405,7 @@ export abstract class WindowedListModel implements WindowedList.IModel {
}

if (align === 'auto') {
if (bottomEdge > itemBottom && topEdge < itemTop) {
if (isFullyWithinViewport) {
// No need to change the position, return the current offset.
return currentOffset;
} else if (alignPreference !== undefined) {
Expand Down

0 comments on commit f7da641

Please sign in to comment.