generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ 206 filter function in select component (#209)
* 206: add filter function to select component * 206: fix format * 206: add close list after click outside * 206: fix format * 206: add noItemFoundMessage --------- Co-authored-by: Fabian Wilms <[email protected]>
- Loading branch information
1 parent
6f0cb6b
commit 0378116
Showing
2 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { onBeforeUnmount, onMounted } from "vue"; | ||
|
||
export default function useOnClickOutside(component: any, callback: any) { | ||
if (!component) return; | ||
const listener = (event: any) => { | ||
if ( | ||
event.target !== component.value && | ||
event.composedPath().includes(component.value) | ||
) { | ||
return; | ||
} | ||
if (typeof callback === "function") { | ||
callback(); | ||
} | ||
}; | ||
onMounted(() => { | ||
window.addEventListener("click", listener); | ||
}); | ||
onBeforeUnmount(() => { | ||
window.removeEventListener("click", listener); | ||
}); | ||
|
||
return { listener }; | ||
} |