forked from vuetifyjs/vuetify
-
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.
fix(VSelect/VAutocomplete/VCombobox): respect click outside (vuetifyj…
…s#20004) fixes vuetifyjs#20003 Co-authored-by: John Leider <[email protected]>
- Loading branch information
Showing
4 changed files
with
55 additions
and
3 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
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,33 @@ | ||
// https://github.com/vuetifyjs/vuetify/issues/20003 | ||
/** | ||
* This composable is designed to track whether the mouse is in a mousedown state at any given time. The original motivation is that | ||
* it is impossible to distinguish whether a blur event is triggered by mousedown, keydown, or via JavaScript. | ||
* This composable allows for conditional logic when a blur is triggered by mousedown. | ||
*/ | ||
|
||
// Utilities | ||
import { onMounted, onUnmounted, shallowRef } from 'vue' | ||
|
||
export function useIsMousedown () { | ||
const isMousedown = shallowRef(false) | ||
|
||
function mousedown () { | ||
isMousedown.value = true | ||
} | ||
|
||
function mouseup () { | ||
isMousedown.value = false | ||
} | ||
|
||
onMounted(() => { | ||
document.body.addEventListener('mousedown', mousedown) | ||
document.body.addEventListener('mouseup', mouseup) | ||
}) | ||
|
||
onUnmounted(() => { | ||
document.body.removeEventListener('mousedown', mousedown) | ||
document.body.removeEventListener('mouseup', mouseup) | ||
}) | ||
|
||
return { isMousedown } | ||
} |