Skip to content

Commit

Permalink
fix(VField): prevent mousedown fall through to root
Browse files Browse the repository at this point in the history
fixes #17280

use clickOutside from vueuse to manually trigger blur
  • Loading branch information
yuwu9145 committed May 13, 2023
1 parent 70c6364 commit 6727c49
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"@vue/compiler-sfc": "^3.2.47",
"@vueuse/core": "^10.1.2",
"@vueuse/head": "^1.1.23",
"babel-eslint": "^10.1.0",
"babel-jest": "^28.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export const VAutocomplete = genericComponent<new <

menu.value = true
}
function onClickAppendInner (e: MouseEvent) {
e.stopPropagation()
menu.value = !menu.value
}
function onKeydown (e: KeyboardEvent) {
if (props.readonly || form?.isReadonly.value) return

Expand Down Expand Up @@ -341,6 +345,7 @@ export const VAutocomplete = genericComponent<new <
placeholder={ isDirty ? undefined : props.placeholder }
onClick:clear={ onClear }
onMousedown:control={ onMousedownControl }
onClick:appendInner={ onClickAppendInner }
onKeydown={ onKeydown }
>
{{
Expand Down
7 changes: 6 additions & 1 deletion packages/vuetify/src/components/VField/VField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const VField = genericComponent<new <T>(props: {
},

emits: {
mousedown: (e: MouseEvent) => true,
'update:focused': (focused: boolean) => true,
'update:modelValue': (val: any) => true,
},
Expand Down Expand Up @@ -266,7 +267,11 @@ export const VField = genericComponent<new <T>(props: {
</div>
)}

<div class="v-field__field" data-no-activator="">
<div
class="v-field__field"
onMousedown={ e => emit('mousedown', e) }
data-no-activator=""
>
{['filled', 'solo', 'solo-inverted', 'solo-filled'].includes(props.variant) && hasLabel.value && (
<VFieldLabel
key="floating-label"
Expand Down
5 changes: 4 additions & 1 deletion packages/vuetify/src/components/VTextField/VTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useProxiedModel } from '@/composables/proxiedModel'
// Utilities
import { cloneVNode, computed, nextTick, ref } from 'vue'
import { callEvent, filterInputAttrs, genericComponent, propsFactory, useRender } from '@/util'
import { onClickOutside } from '@vueuse/core'

// Types
import type { PropType } from 'vue'
Expand Down Expand Up @@ -94,6 +95,9 @@ export const VTextField = genericComponent<Omit<VInputSlots & VFieldSlots, 'defa
const vInputRef = ref<VInput>()
const vFieldRef = ref<VField>()
const inputRef = ref<HTMLInputElement>()

onClickOutside(vInputRef as any, _ => blur())

const isActive = computed(() => (
activeTypes.includes(props.type) ||
props.persistentPlaceholder ||
Expand Down Expand Up @@ -217,7 +221,6 @@ export const VTextField = genericComponent<Omit<VInputSlots & VFieldSlots, 'defa
size={ 1 }
type={ props.type }
onFocus={ onFocus }
onBlur={ blur }
{ ...slotProps }
{ ...inputAttrs }
/>
Expand Down
32 changes: 32 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3427,6 +3427,11 @@
resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.2.tgz#fc25ad9943bcac11cceb8168db4f275e0e72e756"
integrity sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==

"@types/web-bluetooth@^0.0.17":
version "0.0.17"
resolved "https://registry.yarnpkg.com/@types/web-bluetooth/-/web-bluetooth-0.0.17.tgz#5c9f3c617f64a9735d7b72a7cc671e166d900c40"
integrity sha512-4p9vcSmxAayx72yn70joFoL44c9MO/0+iVEBIQXe3v2h2SiAsEIo/G5v6ObFWvNKRFjbrVadNf9LqEEZeQPzdA==

"@types/yargs-parser@*":
version "15.0.0"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-15.0.0.tgz#cb3f9f741869e20cce330ffbeb9271590483882d"
Expand Down Expand Up @@ -3846,6 +3851,16 @@
prettier "^2.4.1"
yargs "^17.3.0"

"@vueuse/core@^10.1.2":
version "10.1.2"
resolved "https://registry.yarnpkg.com/@vueuse/core/-/core-10.1.2.tgz#2499eadec36c5d7109338e3a2b73725040ae8011"
integrity sha512-roNn8WuerI56A5uiTyF/TEYX0Y+VKlhZAF94unUfdhbDUI+NfwQMn4FUnUscIRUhv3344qvAghopU4bzLPNFlA==
dependencies:
"@types/web-bluetooth" "^0.0.17"
"@vueuse/metadata" "10.1.2"
"@vueuse/shared" "10.1.2"
vue-demi ">=0.14.0"

"@vueuse/head@^1.1.23":
version "1.1.23"
resolved "https://registry.yarnpkg.com/@vueuse/head/-/head-1.1.23.tgz#a94a4457aed0768d4e9a595097b9d1716a67962b"
Expand All @@ -3856,6 +3871,18 @@
"@unhead/ssr" "^1.1.23"
"@unhead/vue" "^1.1.23"

"@vueuse/metadata@10.1.2":
version "10.1.2"
resolved "https://registry.yarnpkg.com/@vueuse/metadata/-/metadata-10.1.2.tgz#d8ffe557b1042efd03a0aa88540a00c25d193ee3"
integrity sha512-3mc5BqN9aU2SqBeBuWE7ne4OtXHoHKggNgxZR2K+zIW4YLsy6xoZ4/9vErQs6tvoKDX6QAqm3lvsrv0mczAwIQ==

"@vueuse/shared@10.1.2":
version "10.1.2"
resolved "https://registry.yarnpkg.com/@vueuse/shared/-/shared-10.1.2.tgz#31d8733a217a6396eb67706319133bf62cdd8baa"
integrity sha512-1uoUTPBlgyscK9v6ScGeVYDDzlPSFXBlxuK7SfrDGyUTBiznb3mNceqhwvZHjtDRELZEN79V5uWPTF1VDV8svA==
dependencies:
vue-demi ">=0.14.0"

"@yankeeinlondon/builder-api@^1.2.1", "@yankeeinlondon/builder-api@^1.3.4":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@yankeeinlondon/builder-api/-/builder-api-1.4.1.tgz#0768ded0c24233df4275e66fc4996cbdee5e1000"
Expand Down Expand Up @@ -14143,6 +14170,11 @@ vue-demi@*, vue-demi@^0.13.11:
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.13.11.tgz#7d90369bdae8974d87b1973564ad390182410d99"
integrity sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==

vue-demi@>=0.14.0:
version "0.14.1"
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.14.1.tgz#1ed9af03a27642762bfed83d8750805302d0398d"
integrity sha512-rt+yuCtXvscYot9SQQj3WKZJVSriPNqVkpVBNEHPzSgBv7QIYzsS410VqVgvx8f9AAPgjg+XPKvmV3vOqqkJQQ==

vue-eslint-parser@^9.0.1:
version "9.0.2"
resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-9.0.2.tgz#d2535516f3f55adb387939427fe741065eb7948a"
Expand Down

0 comments on commit 6727c49

Please sign in to comment.