Skip to content

Commit dbf95b8

Browse files
committed
Fix drawer story
The original implementation was relying on a quirk of how the container rect used to be measured without considering transforms. The new measuring strategy is no longer transform agnostic, therefore we cannot rely on the `top` coordinates of the container node rect as they include transforms. In the future, it may be possible to open up configuring how the container node rect is measured to consumers if the need arises.
1 parent 025318e commit dbf95b8

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

stories/3 - Examples/Drawer/Drawer.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $content-background-color: #fefefe;
2020
flex-direction: column;
2121
width: 100%;
2222
max-width: 500px;
23-
max-height: 75vh;
23+
max-height: var(--max-height);
2424
transition: transform 200ms ease;
2525
transform: translate3d(
2626
0,

stories/3 - Examples/Drawer/Sheet.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import classNames from 'classnames';
33
import {useDraggable} from '@dnd-kit/core';
44

55
import {Header} from './Header';
6+
import {MAX_DRAWER_HEIGHT_PERCENT} from './constants';
67

78
import styles from './Drawer.module.css';
89

@@ -31,6 +32,7 @@ export function Sheet({children, expanded, header}: Props) {
3132
})}
3233
style={
3334
{
35+
'--max-height': `${MAX_DRAWER_HEIGHT_PERCENT * 100}vh`,
3436
'--transform': transform ? `${transform.y}px` : undefined,
3537
} as React.CSSProperties
3638
}

stories/3 - Examples/Drawer/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ export enum Region {
22
Collapse = 'collapse',
33
Expand = 'expand',
44
}
5+
6+
export const MAX_DRAWER_HEIGHT_PERCENT = 0.75;

stories/3 - Examples/Drawer/modifiers.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import type {ClientRect, Modifier} from '@dnd-kit/core';
22
import type {Transform} from '@dnd-kit/utilities';
33

4+
import {MAX_DRAWER_HEIGHT_PERCENT} from './constants';
5+
46
export const rubberbandModifier: Modifier = ({
5-
containerNodeRect,
67
draggingNodeRect,
78
transform,
9+
windowRect,
810
}) => {
9-
if (!draggingNodeRect || !containerNodeRect) {
11+
if (!draggingNodeRect || !windowRect) {
1012
return transform;
1113
}
1214

13-
return rubberbandBoundingRect(transform, draggingNodeRect, containerNodeRect);
15+
return rubberbandBoundingRect(transform, draggingNodeRect, {
16+
...windowRect,
17+
top: (1 - MAX_DRAWER_HEIGHT_PERCENT) * windowRect.height,
18+
height: MAX_DRAWER_HEIGHT_PERCENT * windowRect.height,
19+
});
1420
};
1521

1622
function rubberbandBoundingRect(

0 commit comments

Comments
 (0)