Replace vue-multiselect with a custom component (#366)
Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/366 Co-authored-by: konrad <konrad@kola-entertainments.de> Co-committed-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
27
src/helpers/closeWhenClickedOutside.js
Normal file
27
src/helpers/closeWhenClickedOutside.js
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Calls the close callback when a click happened outside of the rootElement.
|
||||
*
|
||||
* @param event The "click" event object.
|
||||
* @param rootElement
|
||||
* @param closeCallback A closure function to call when the click event happened outside of the rootElement.
|
||||
*/
|
||||
export const closeWhenClickedOutside = (event, rootElement, closeCallback) => {
|
||||
// We walk up the tree to see if any parent of the clicked element is the root element.
|
||||
// If it is not, we call the close callback. We're doing all this hassle to only call the
|
||||
// closing callback when a click happens outside of the rootElement.
|
||||
let parent = event.target.parentElement
|
||||
while (parent !== rootElement) {
|
||||
if (parent.parentElement === null) {
|
||||
parent = null
|
||||
break
|
||||
}
|
||||
|
||||
parent = parent.parentElement
|
||||
}
|
||||
|
||||
if (parent === rootElement) {
|
||||
return
|
||||
}
|
||||
|
||||
closeCallback()
|
||||
}
|
Reference in New Issue
Block a user