mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 10:44:59 +00:00
chore: add src-next folder
This commit is contained in:
21
src-next/hooks/use-click-outside.ts
Normal file
21
src-next/hooks/use-click-outside.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Ref } from 'vue';
|
||||
import { useGlobalEvent } from './use-global-event';
|
||||
|
||||
export type UseClickOutsideOpitons = {
|
||||
event: string;
|
||||
callback: EventListener;
|
||||
element: Ref<Element>;
|
||||
flag?: Ref<boolean>;
|
||||
};
|
||||
|
||||
export function useClickOutside(options: UseClickOutsideOpitons) {
|
||||
const { event = 'click', callback, element, flag } = options;
|
||||
|
||||
function onClick(event: Event) {
|
||||
if (!element.value.contains(event.target as Node)) {
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
useGlobalEvent(document, event, onClick, false, flag);
|
||||
}
|
Reference in New Issue
Block a user