@pushwoosh/kit-helpers 4.8.4 → 4.8.5
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/hooks/useClickAway.d.ts +1 -1
- package/hooks/useClickAway.js +2 -2
- package/package.json +1 -1
package/hooks/useClickAway.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ type ClickAwayCallback = (event: MouseEvent | TouchEvent) => void;
|
|
|
7
7
|
* @param listener The callback function to execute when the event occurs.
|
|
8
8
|
* @returns A function to remove the added event listeners.
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function elementAddListener<K extends keyof HTMLElementEventMap, E extends HTMLElement>(element: E | Document, // Allow Document as well
|
|
11
11
|
eventNames: K | K[], listener: (this: E | Document, ev: HTMLElementEventMap[K]) => void): () => void;
|
|
12
12
|
/**
|
|
13
13
|
* Subscribes to mousedown/touchstart events outside a given element.
|
package/hooks/useClickAway.js
CHANGED
|
@@ -7,7 +7,7 @@ import usePersistentFunction from './usePersistentFunction';
|
|
|
7
7
|
* @param listener The callback function to execute when the event occurs.
|
|
8
8
|
* @returns A function to remove the added event listeners.
|
|
9
9
|
*/
|
|
10
|
-
export function
|
|
10
|
+
export function elementAddListener(element,
|
|
11
11
|
// Allow Document as well
|
|
12
12
|
eventNames, listener) {
|
|
13
13
|
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
|
|
@@ -28,7 +28,7 @@ eventNames, listener) {
|
|
|
28
28
|
*/
|
|
29
29
|
export function subscribeClickAway(element, callback) {
|
|
30
30
|
// Use document directly, no need for 'any' cast
|
|
31
|
-
return
|
|
31
|
+
return elementAddListener(document, ['mousedown', 'touchstart'], event => {
|
|
32
32
|
// Type assertion for event target
|
|
33
33
|
const target = event.target;
|
|
34
34
|
// Check if the element exists and the click target is outside the element
|