Skip to content

Commit

Permalink
fix: opacity calculation (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilkowalski authored Sep 24, 2024
1 parent 4a4c85a commit 32024ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export function Root({
const previousDiffFromInitial = React.useRef(0);
const drawerRef = React.useRef<HTMLDivElement>(null);
const drawerHeightRef = React.useRef(drawerRef.current?.getBoundingClientRect().height || 0);
const drawerWidthRef = React.useRef(drawerRef.current?.getBoundingClientRect().width || 0);
const initialDrawerHeight = React.useRef(0);

const onSnapPointChange = React.useCallback((activeSnapPointIndex: number) => {
Expand Down Expand Up @@ -187,6 +188,7 @@ export function Root({
if (drawerRef.current && !drawerRef.current.contains(event.target as Node)) return;

drawerHeightRef.current = drawerRef.current?.getBoundingClientRect().height || 0;
drawerWidthRef.current = drawerRef.current?.getBoundingClientRect().width || 0;
setIsDragging(true);
dragStartTime.current = new Date();

Expand Down Expand Up @@ -288,9 +290,11 @@ export function Root({
// We need to capture last time when drag with scroll was triggered and have a timeout between
const absDraggedDistance = Math.abs(draggedDistance);
const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
const drawerDimension =
direction === 'bottom' || direction === 'top' ? drawerHeightRef.current : drawerWidthRef.current;

// Calculate the percentage dragged, where 1 is the closed position
let percentageDragged = absDraggedDistance / drawerHeightRef.current;
let percentageDragged = absDraggedDistance / drawerDimension;
const snapPointPercentageDragged = getSnapPointsPercentageDragged(absDraggedDistance, isDraggingInDirection);

if (snapPointPercentageDragged !== null) {
Expand Down
2 changes: 1 addition & 1 deletion test/src/app/scrollable-with-inputs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Drawer } from 'vaul';
export default function Page() {
return (
<div className="w-screen h-screen bg-white p-8 flex justify-center items-center" data-vaul-drawer-wrapper="">
<Drawer.Root autoFocus={true}>
<Drawer.Root>
<Drawer.Trigger asChild>
<button>Open Drawer</button>
</Drawer.Trigger>
Expand Down

0 comments on commit 32024ab

Please sign in to comment.