react-modal-sheet 5.2.3 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.2.3",
2
+ "version": "5.3.1",
3
3
  "license": "MIT",
4
4
  "name": "react-modal-sheet",
5
5
  "description": "Flexible bottom sheet component for your React apps",
@@ -57,23 +57,23 @@
57
57
  },
58
58
  "devDependencies": {
59
59
  "@arethetypeswrong/cli": "0.18.2",
60
- "@biomejs/biome": "2.2.5",
61
- "@types/react": "19.2.2",
62
- "@types/react-dom": "19.2.1",
63
- "@vitejs/plugin-react": "5.0.4",
60
+ "@biomejs/biome": "2.4.5",
61
+ "@types/react": "19.2.14",
62
+ "@types/react-dom": "19.2.3",
63
+ "@vitejs/plugin-react": "5.1.4",
64
64
  "husky": "9.1.7",
65
- "jsdom": "27.0.0",
66
- "motion": "12.23.22",
65
+ "jsdom": "28.1.0",
66
+ "motion": "12.35.0",
67
67
  "npm-run-all": "4.1.5",
68
- "react": "19.2.0",
69
- "react-dom": "19.2.0",
70
- "tsup": "8.5.0",
68
+ "react": "19.2.4",
69
+ "react-dom": "19.2.4",
70
+ "tsup": "8.5.1",
71
71
  "typescript": "5.9.3",
72
- "vite": "7.1.9",
73
- "vitest": "3.2.4"
72
+ "vite": "7.3.1",
73
+ "vitest": "4.0.18"
74
74
  },
75
75
  "engines": {
76
- "node": ">=18"
76
+ "node": ">=20"
77
77
  },
78
78
  "prettier": {
79
79
  "printWidth": 80,
@@ -1,9 +1,9 @@
1
1
  import { motion } from 'motion/react';
2
2
  import React, { forwardRef } from 'react';
3
3
 
4
- import { SheetDragIndicator } from './SheetDragIndicator';
5
4
  import { useSheetContext } from './context';
6
5
  import { useDragConstraints } from './hooks/use-drag-constraints';
6
+ import { SheetDragIndicator } from './SheetDragIndicator';
7
7
  import { styles } from './styles';
8
8
  import { type SheetHeaderProps } from './types';
9
9
  import { applyStyles, mergeRefs } from './utils';
package/src/debug.ts CHANGED
@@ -4,14 +4,14 @@
4
4
  * and hide it when that element is clicked. Create the element if it doesn't exist,
5
5
  * and update its content with the payload (any JSON data).
6
6
  */
7
- export function debug(payload: any) {
7
+ export function debug(payload: any, placement: 'top' | 'bottom' = 'bottom') {
8
8
  let debugElement = document.getElementById('debug-element');
9
9
 
10
10
  if (!debugElement) {
11
11
  debugElement = document.createElement('div');
12
12
  debugElement.id = 'debug-element';
13
13
  debugElement.style.position = 'fixed';
14
- debugElement.style.bottom = '0';
14
+ debugElement.style[placement] = '0';
15
15
  debugElement.style.left = '0';
16
16
  debugElement.style.width = '100%';
17
17
  debugElement.style.maxHeight = '50%';
package/src/sheet.tsx CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  } from 'motion/react';
10
10
  import React, {
11
11
  forwardRef,
12
+ useEffect,
12
13
  useImperativeHandle,
13
14
  useRef,
14
15
  useState,
@@ -276,6 +277,55 @@ export const Sheet = forwardRef<any, SheetProps>(
276
277
  snapTo,
277
278
  }));
278
279
 
280
+ /**
281
+ * If the keyboard is opened while we are in a snap point we need to ensure
282
+ * the sheet content is not covered by the keyboard due to being at a lower
283
+ * snap point. We move the sheet up enough to ensure the content is visible
284
+ * and move it back down when the keyboard closes.
285
+ */
286
+ useEffect(() => {
287
+ if (
288
+ isOpen &&
289
+ snapPoints.length > 0 &&
290
+ avoidKeyboard &&
291
+ keyboard.isKeyboardOpen
292
+ ) {
293
+ const focusedElement = document.activeElement as HTMLElement | null;
294
+ const visibleSheetHeight = yInverted.get() - keyboard.keyboardHeight;
295
+
296
+ // If the keyboard is covering the sheet content, move the sheet up to reveal it
297
+ if (visibleSheetHeight <= 0 && focusedElement) {
298
+ const currentY = y.get();
299
+ const diffY = Math.max(currentY - Math.abs(visibleSheetHeight), 0);
300
+
301
+ /**
302
+ * Get the position of the focused input relative to the sheet container
303
+ * and calculate how much we need to move the sheet up to ensure
304
+ * the focused input is visible above the keyboard.
305
+ *
306
+ * NOTE: RAF is needed to ensure the `top` values are correct.
307
+ */
308
+ requestAnimationFrame(() => {
309
+ const inputRect = focusedElement.getBoundingClientRect();
310
+ const sheetRect = sheetRef.current?.getBoundingClientRect();
311
+
312
+ let inputOffset = 0;
313
+
314
+ if (sheetRect) {
315
+ inputOffset = inputRect.top - sheetRect.top + inputRect.height;
316
+ }
317
+
318
+ animate(y, diffY - inputOffset, animationOptions);
319
+ });
320
+
321
+ // When keyboard closes animate back to the original snap point
322
+ return () => {
323
+ animate(y, currentY, animationOptions);
324
+ };
325
+ }
326
+ }
327
+ }, [isOpen, keyboard.isKeyboardOpen]);
328
+
279
329
  useModalEffect({
280
330
  y,
281
331
  detent,