Skip to content

Commit

Permalink
fix: correct range input behavior, fixes #64
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Apr 16, 2022
1 parent 1ed83c4 commit 0bd6ca8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/SideEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ export function RemoveScrollSideCar(props: IRemoveScrollEffectProps) {
const moveDirection: Axis =
Math.abs(deltaX) > Math.abs(deltaY) ? 'h' : 'v';

// allow horizontal touch move on Range inputs. They will not cause any scroll
if ('touches' in event && moveDirection === 'h' && (target as HTMLInputElement).type === 'range') {
return false;
}


let canBeScrolledInMainDirection = locationCouldBeScrolled(
moveDirection,
target
Expand Down
5 changes: 1 addition & 4 deletions src/handleScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const elementCouldBeVScrolled = (node: HTMLElement): boolean => {

const elementCouldBeHScrolled = (node: HTMLElement): boolean => {
const styles = window.getComputedStyle(node);
// we allow horizontal scroll on range elements
if ((node as HTMLInputElement).type === "range") {
return true;
}

return (
styles.overflowX !== 'hidden' && // not-not-scrollable
!(styles.overflowY === styles.overflowX && styles.overflowX === 'visible') // scrollable
Expand Down

0 comments on commit 0bd6ca8

Please sign in to comment.