Skip to content

Commit

Permalink
fix(inputs): add missing update:focused events (#16852)
Browse files Browse the repository at this point in the history
Co-authored-by: John Leider <[email protected]>
  • Loading branch information
blalan05 and johnleider authored Apr 19, 2023
1 parent 28a1763 commit 42c0b4d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const VAutocomplete = genericComponent<new <
},

emits: {
'update:focused': (focused: boolean) => true,
'update:search': (val: any) => true,
'update:modelValue': (val: any) => true,
'update:menu': (val: boolean) => true,
Expand Down
1 change: 1 addition & 0 deletions packages/vuetify/src/components/VCombobox/VCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const VCombobox = genericComponent<new <
},

emits: {
'update:focused': (focused: boolean) => true,
'update:modelValue': (val: any) => true,
'update:search': (val: string) => true,
'update:menu': (val: boolean) => true,
Expand Down
10 changes: 5 additions & 5 deletions packages/vuetify/src/components/VFileInput/VFileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { VField } from '@/components/VField'

// Composables
import { forwardRefs } from '@/composables/forwardRefs'
import { useFocus } from '@/composables/focus'
import { useLocale } from '@/composables/locale'
import { useProxiedModel } from '@/composables/proxiedModel'

Expand Down Expand Up @@ -78,12 +79,14 @@ export const VFileInput = genericComponent<VFileInputSlots>()({
emits: {
'click:control': (e: MouseEvent) => true,
'mousedown:control': (e: MouseEvent) => true,
'update:focused': (focused: boolean) => true,
'update:modelValue': (files: File[]) => true,
},

setup (props, { attrs, emit, slots }) {
const { t } = useLocale()
const model = useProxiedModel(props, 'modelValue')
const { isFocused, focus, blur } = useFocus(props)
const base = computed(() => typeof props.showSize !== 'boolean' ? props.showSize : undefined)
const totalBytes = computed(() => (model.value ?? []).reduce((bytes, { size = 0 }) => bytes + size, 0))
const totalBytesReadable = computed(() => humanReadableFileSize(totalBytes.value, base.value))
Expand All @@ -103,16 +106,13 @@ export const VFileInput = genericComponent<VFileInputSlots>()({
})
const vInputRef = ref<VInput>()
const vFieldRef = ref<VInput>()
const isFocused = ref(false)
const inputRef = ref<HTMLInputElement>()
function onFocus () {
if (inputRef.value !== document.activeElement) {
inputRef.value?.focus()
}

if (!isFocused.value) {
isFocused.value = true
}
if (!isFocused.value) focus()
}
function onClickPrepend (e: MouseEvent) {
onControlClick(e)
Expand Down Expand Up @@ -212,7 +212,7 @@ export const VFileInput = genericComponent<VFileInputSlots>()({
model.value = [...target.files ?? []]
}}
onFocus={ onFocus }
onBlur={ () => (isFocused.value = false) }
onBlur={ blur }
{ ...slotProps }
{ ...inputAttrs }
/>
Expand Down
2 changes: 2 additions & 0 deletions packages/vuetify/src/components/VSelect/VSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const VSelect = genericComponent<new <
},

emits: {
'update:focused': (focused: boolean) => true,
'update:modelValue': (val: any) => true,
'update:menu': (val: boolean) => true,
},
Expand Down Expand Up @@ -405,6 +406,7 @@ export const VSelect = genericComponent<new <
})

return forwardRefs({
isFocused,
menu,
select,
}, vTextFieldRef)
Expand Down
5 changes: 3 additions & 2 deletions packages/vuetify/src/composables/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { useProxiedModel } from '@/composables/proxiedModel'

// Utilities
import { computed } from 'vue'
import { getCurrentInstanceName, propsFactory } from '@/util'
import { EventProp, getCurrentInstanceName, propsFactory } from '@/util'

// Types
export interface FocusProps {
focused: boolean
'onUpdate:focused': ((val: boolean) => void) | undefined
'onUpdate:focused': ((focused: boolean) => any) | undefined
}

// Composables
export const makeFocusProps = propsFactory({
focused: Boolean,
'onUpdate:focused': EventProp<[FocusEvent]>(),
}, 'focus')

export function useFocus (
Expand Down

0 comments on commit 42c0b4d

Please sign in to comment.