react-modal-sheet 5.4.0 → 5.5.0

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.
@@ -1,46 +0,0 @@
1
- import { type RefObject, useEffect, useState } from 'react';
2
-
3
- export function useFocusedInput({
4
- isEnabled,
5
- sheetRef,
6
- }: {
7
- isEnabled: boolean;
8
- sheetRef: RefObject<HTMLElement | null>;
9
- }) {
10
- const [focusedInput, setFocusedInput] = useState<HTMLElement | null>(null);
11
-
12
- // Keep track of the currently focused input within the sheet
13
- useEffect(() => {
14
- if (!isEnabled) return;
15
-
16
- const handleFocusIn = (event: FocusEvent) => {
17
- const focusedElement = event.target as HTMLElement;
18
-
19
- const isInput =
20
- focusedElement?.tagName === 'INPUT' ||
21
- focusedElement?.tagName === 'TEXTAREA';
22
-
23
- if (isInput && sheetRef.current?.contains(focusedElement)) {
24
- setFocusedInput(focusedElement);
25
- }
26
- };
27
-
28
- const handleFocusOut = (event: FocusEvent) => {
29
- const focusedElement = event.target as HTMLElement;
30
-
31
- if (focusedElement === focusedInput) {
32
- setFocusedInput(null);
33
- }
34
- };
35
-
36
- document.addEventListener('focusin', handleFocusIn);
37
- document.addEventListener('focusout', handleFocusOut);
38
-
39
- return () => {
40
- document.removeEventListener('focusin', handleFocusIn);
41
- document.removeEventListener('focusout', handleFocusOut);
42
- };
43
- }, [isEnabled, focusedInput]);
44
-
45
- return focusedInput;
46
- }