Skip to content

Commit

Permalink
Unconditionally preventDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Oct 16, 2024
1 parent e292a1a commit 21c51cf
Showing 1 changed file with 2 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { useScrollAreaRootContext } from '../Root/ScrollAreaRootContext';
import { mergeReactProps } from '../../utils/mergeReactProps';
import { useEnhancedEffect } from '../../utils/useEnhancedEffect';

export function useScrollAreaScrollbar(params: useScrollAreaScrollbar.Parameters) {
const { orientation } = params;
Expand All @@ -19,8 +18,6 @@ export function useScrollAreaScrollbar(params: useScrollAreaScrollbar.Parameters
type,
} = useScrollAreaRootContext();

const [overscrollStyles, setOverscrollStyles] = React.useState<React.CSSProperties>({});

React.useEffect(() => {
const viewportEl = viewportRef.current;
const scrollbarEl = orientation === 'vertical' ? scrollbarYRef.current : scrollbarXRef.current;
Expand All @@ -30,6 +27,8 @@ export function useScrollAreaScrollbar(params: useScrollAreaScrollbar.Parameters
return;
}

event.preventDefault();

if (orientation === 'vertical') {
if (viewportEl.scrollTop === 0 && event.deltaY < 0) {
return;
Expand All @@ -52,8 +51,6 @@ export function useScrollAreaScrollbar(params: useScrollAreaScrollbar.Parameters
return;
}

event.preventDefault();

if (orientation === 'vertical') {
viewportEl.scrollTop += event.deltaY;
} else {
Expand All @@ -68,21 +65,6 @@ export function useScrollAreaScrollbar(params: useScrollAreaScrollbar.Parameters
};
}, [orientation, scrollbarXRef, scrollbarYRef, thumbYRef, viewportRef]);

useEnhancedEffect(() => {
if (!viewportRef.current) {
return;
}

const computedStyle = getComputedStyle(viewportRef.current);

setOverscrollStyles({
['overscrollBehaviorX' as string]: computedStyle.overscrollBehaviorX,
['overscrollBehaviorY' as string]: computedStyle.overscrollBehaviorY,
['overscrollBehaviorBlock' as string]: computedStyle.overscrollBehaviorBlock,
['overscrollBehaviorInline' as string]: computedStyle.overscrollBehaviorInline,
});
}, [viewportRef]);

const getScrollbarProps = React.useCallback(
(externalProps = {}) =>
mergeReactProps<'div'>(externalProps, {
Expand Down Expand Up @@ -145,8 +127,6 @@ export function useScrollAreaScrollbar(params: useScrollAreaScrollbar.Parameters
onPointerUp: handlePointerUp,
style: {
position: 'absolute',
overflow: 'scroll',
...overscrollStyles,
...(type === 'inlay' && { touchAction: 'none' }),
...(orientation === 'vertical' && {
top: 0,
Expand All @@ -163,7 +143,6 @@ export function useScrollAreaScrollbar(params: useScrollAreaScrollbar.Parameters
[
rootId,
handlePointerUp,
overscrollStyles,
type,
orientation,
dir,
Expand Down

0 comments on commit 21c51cf

Please sign in to comment.