Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/handleScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ const getDirectionFactor = (axis: Axis, direction: string | null) =>
*/
axis === 'h' && direction === 'rtl' ? -1 : 1;

const elementIsReverseScrolled = (node: Element): boolean => {
if (!(node instanceof Element)) {
return false;
}

const styles = window.getComputedStyle(node);

return styles.flexDirection === 'column-reverse' || styles.flexDirection === 'row-reverse';
};

export const handleScroll = (
axis: Axis,
endTarget: HTMLElement,
Expand Down Expand Up @@ -106,8 +116,14 @@ export const handleScroll = (

if (position || elementScroll) {
if (elementCouldBeScrolled(axis, target)) {
availableScroll += elementScroll;
availableScrollTop += position;
if (elementIsReverseScrolled(target)) {
// For column-reverse/row-reverse, swap the available scroll calculations
availableScroll += position;
availableScrollTop += elementScroll;
} else {
availableScroll += elementScroll;
availableScrollTop += position;
}
}
}

Expand Down