Skip to content

Commit f6c342a

Browse files
authored
fix: correct even in useFocusableControl (#4484)
1 parent 8d87159 commit f6c342a

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

packages/ui/src/components/va-input/VaInput.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,12 @@ import type { AnyStringPropType } from '../../utils/types/prop-type'
6969
import { VaInputWrapper } from '../va-input-wrapper'
7070
import { VaIcon } from '../va-icon'
7171
import { combineFunctions } from '../../utils/combine-functions'
72-
import { omit } from '../../utils/omit'
7372
import { pick } from '../../utils/pick'
7473
7574
const VaInputWrapperProps = extractComponentProps(VaInputWrapper)
7675
7776
const { createEmits: createInputEmits, createListeners: createInputListeners } = useEmitProxy(
78-
['change', 'keyup', 'keypress', 'keydown', 'focus', 'blur', 'input'],
77+
['change', 'keyup', 'keypress', 'keydown', 'input'],
7978
)
8079
8180
const { createEmits: createFieldEmits, createListeners: createFieldListeners } = useEmitProxy([
@@ -178,7 +177,7 @@ const inputListeners = createInputListeners(emit)
178177
179178
const inputEvents = {
180179
...inputListeners,
181-
onBlur: combineFunctions(onBlur, inputListeners.onBlur),
180+
onBlur,
182181
}
183182
184183
const setInputValue = (newValue: string) => {

packages/ui/src/composables/fabrics/useFocusableControl.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ export const useFocusableControl = (
1515
autofocus: boolean,
1616
disabled?: boolean,
1717
},
18-
emit: (event: (typeof useFocusableControlEmits)[number]) => void,
18+
emit: (event: (typeof useFocusableControlEmits)[number], e: FocusEvent) => void,
1919
) => {
20-
const isFocused = useElementFocused(el)
20+
const isFocused = useElementFocused(el, {
21+
onBlur (e) {
22+
emit('blur', e)
23+
},
24+
onFocus (e) {
25+
emit('focus', e)
26+
},
27+
})
2128

2229
const focus = () => {
2330
if (props.disabled) { return }
@@ -37,14 +44,6 @@ export const useFocusableControl = (
3744
}
3845
})
3946

40-
watch(isFocused, (value) => {
41-
if (value) {
42-
emit('focus')
43-
} else {
44-
emit('blur')
45-
}
46-
})
47-
4847
return {
4948
focus,
5049
blur,

packages/ui/src/composables/std/browser/useElementFocused.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@ import { focusElement, blurElement } from '../../../utils/focus'
44
import { unwrapEl } from '../../../utils/unwrapEl'
55
import { TemplateRef } from '../../../utils/types/template-ref'
66

7-
export const useElementFocused = (el: Ref<TemplateRef>) => {
7+
export const useElementFocused = (
8+
el: Ref<TemplateRef>,
9+
options: {
10+
onFocus?: (e: FocusEvent) => void,
11+
onBlur?: (e: FocusEvent) => void
12+
} = {},
13+
) => {
814
const isFocused = ref(false)
915

10-
useEvent('focus', () => {
16+
useEvent('focus', (e) => {
1117
isFocused.value = true
18+
options.onFocus?.(e)
1219
}, el)
1320

14-
useEvent('blur', () => {
21+
useEvent('blur', (e) => {
1522
isFocused.value = false
23+
options.onBlur?.(e)
1624
}, el)
1725

1826
return computed({

0 commit comments

Comments
 (0)