Skip to content

Commit

Permalink
fix(lists): fix lists not working properly with few elements with sti…
Browse files Browse the repository at this point in the history
…ck-to-start
  • Loading branch information
pierpo committed Apr 30, 2024
1 parent 4018d5d commit bd9d139
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export const getLastLeftItemIndex = <T>(

return 0;
}
return data.length - Math.floor(listSizeInPx / itemSizeInPx);

const result = data.length - Math.floor(listSizeInPx / itemSizeInPx);

if (result < 0) {
return 0;
}
return result;
};

/**
Expand Down Expand Up @@ -88,6 +94,11 @@ export const getLastRightItemIndex = <T>(

return data.length - 1;
}
// We substract 1 because index starts from 0
return Math.floor(listSizeInPx / itemSizeInPx) - 1;
const result = Math.floor(listSizeInPx / itemSizeInPx) - 1;

if (result > data.length - 1) {
// We substract 1 because index starts from 0
return data.length - 1;
}
return result;
};

0 comments on commit bd9d139

Please sign in to comment.