mirror of
https://github.com/element-plus/element-plus.git
synced 2025-08-18 14:12:56 +08:00
fix(components): [input] blur event fails when using textarea (#17836)
closed #17825
This commit is contained in:
@ -331,21 +331,67 @@ describe('Input.vue', () => {
|
|||||||
const handleFocus = vi.fn()
|
const handleFocus = vi.fn()
|
||||||
const handleBlur = vi.fn()
|
const handleBlur = vi.fn()
|
||||||
|
|
||||||
test('event:focus & blur', async () => {
|
test('event:focus', async () => {
|
||||||
const content = ref('')
|
const content = ref('')
|
||||||
const wrapper = mount(() => (
|
const wrapper = mount(() => (
|
||||||
<Input
|
<Input
|
||||||
placeholder="请输入内容"
|
placeholder="请输入内容"
|
||||||
modelValue={content.value}
|
modelValue={content.value}
|
||||||
onFocus={handleFocus}
|
onFocus={handleFocus}
|
||||||
onBlur={handleBlur}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
|
|
||||||
const input = wrapper.find('input')
|
const input = wrapper.find('input')
|
||||||
|
|
||||||
await input.trigger('focus')
|
await input.trigger('focus')
|
||||||
expect(handleFocus).toBeCalled()
|
expect(handleFocus).toHaveBeenCalledOnce()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('event:blur', async () => {
|
||||||
|
const content = ref('')
|
||||||
|
const wrapper = mount(() => (
|
||||||
|
<Input
|
||||||
|
placeholder="请输入内容"
|
||||||
|
modelValue={content.value}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
|
||||||
|
const input = wrapper.find('input')
|
||||||
|
|
||||||
|
await input.trigger('blur')
|
||||||
|
expect(handleBlur).toHaveBeenCalledOnce()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('textarea & event:focus', async () => {
|
||||||
|
const content = ref('')
|
||||||
|
const wrapper = mount(() => (
|
||||||
|
<Input
|
||||||
|
type="textarea"
|
||||||
|
placeholder="请输入内容"
|
||||||
|
modelValue={content.value}
|
||||||
|
onFocus={handleFocus}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
|
||||||
|
const input = wrapper.find('textarea')
|
||||||
|
|
||||||
|
await input.trigger('focus')
|
||||||
|
expect(handleFocus).toHaveBeenCalledOnce()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('textarea & event:blur', async () => {
|
||||||
|
const content = ref('')
|
||||||
|
const wrapper = mount(() => (
|
||||||
|
<Input
|
||||||
|
type="textarea"
|
||||||
|
placeholder="请输入内容"
|
||||||
|
modelValue={content.value}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
|
||||||
|
const input = wrapper.find('textarea')
|
||||||
|
|
||||||
await input.trigger('blur')
|
await input.trigger('blur')
|
||||||
expect(handleBlur).toBeCalled()
|
expect(handleBlur).toBeCalled()
|
||||||
|
@ -130,6 +130,8 @@
|
|||||||
@compositionupdate="handleCompositionUpdate"
|
@compositionupdate="handleCompositionUpdate"
|
||||||
@compositionend="handleCompositionEnd"
|
@compositionend="handleCompositionEnd"
|
||||||
@input="handleInput"
|
@input="handleInput"
|
||||||
|
@focus="handleFocus"
|
||||||
|
@blur="handleBlur"
|
||||||
@change="handleChange"
|
@change="handleChange"
|
||||||
@keydown="handleKeydown"
|
@keydown="handleKeydown"
|
||||||
/>
|
/>
|
||||||
@ -257,13 +259,17 @@ const textareaCalcStyle = shallowRef(props.inputStyle)
|
|||||||
|
|
||||||
const _ref = computed(() => input.value || textarea.value)
|
const _ref = computed(() => input.value || textarea.value)
|
||||||
|
|
||||||
const { wrapperRef, isFocused } = useFocusController(_ref, {
|
// wrapperRef for type="text", handleFocus and handleBlur for type="textarea"
|
||||||
|
const { wrapperRef, isFocused, handleFocus, handleBlur } = useFocusController(
|
||||||
|
_ref,
|
||||||
|
{
|
||||||
afterBlur() {
|
afterBlur() {
|
||||||
if (props.validateEvent) {
|
if (props.validateEvent) {
|
||||||
elFormItem?.validate?.('blur').catch((err) => debugWarn(err))
|
elFormItem?.validate?.('blur').catch((err) => debugWarn(err))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const needStatusIcon = computed(() => elForm?.statusIcon ?? false)
|
const needStatusIcon = computed(() => elForm?.statusIcon ?? false)
|
||||||
const validateState = computed(() => elFormItem?.validateState || '')
|
const validateState = computed(() => elFormItem?.validateState || '')
|
||||||
|
Reference in New Issue
Block a user