From ea926472df25fbb6d64431481e6742f0673dc5b3 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Thu, 5 Mar 2026 19:08:29 +0800 Subject: [PATCH] feat(components): [input] textarea supports clearing effects (#23723) * feat(components): [input] textarea supports clearing effects * Update packages/components/input/__tests__/input.test.tsx Co-authored-by: rzzf * feat: update * Apply suggestions from code review Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> * style: update * Update packages/components/input/src/input.vue Co-authored-by: rzzf --------- Co-authored-by: rzzf Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> --- docs/en-US/component/input.md | 2 +- docs/examples/input/clear-icon.vue | 30 +++++++++++--- docs/examples/input/clearable.vue | 30 +++++++++++--- .../components/input/__tests__/input.test.tsx | 39 ++++++++++++++----- packages/components/input/src/input.vue | 14 ++++++- packages/theme-chalk/src/input.scss | 23 +++++++++++ 6 files changed, 115 insertions(+), 23 deletions(-) diff --git a/docs/en-US/component/input.md b/docs/en-US/component/input.md index 8ffed0f367..3f5c4121f1 100644 --- a/docs/en-US/component/input.md +++ b/docs/en-US/component/input.md @@ -25,7 +25,7 @@ input/disabled ## Clearable -:::demo Make the Input clearable with the `clearable` attribute. +:::demo Make the Input clearable with the `clearable` attribute. After version ^(2.13.4), the clearable feature is also available for textarea type of Input. input/clearable diff --git a/docs/examples/input/clear-icon.vue b/docs/examples/input/clear-icon.vue index 945e7ee71c..28a3b172ec 100644 --- a/docs/examples/input/clear-icon.vue +++ b/docs/examples/input/clear-icon.vue @@ -1,10 +1,19 @@ + + diff --git a/docs/examples/input/clearable.vue b/docs/examples/input/clearable.vue index 0a594019b5..d90a1194ed 100644 --- a/docs/examples/input/clearable.vue +++ b/docs/examples/input/clearable.vue @@ -1,14 +1,32 @@ + + diff --git a/packages/components/input/__tests__/input.test.tsx b/packages/components/input/__tests__/input.test.tsx index 27e1370387..fe1605ef29 100644 --- a/packages/components/input/__tests__/input.test.tsx +++ b/packages/components/input/__tests__/input.test.tsx @@ -457,28 +457,49 @@ describe('Input.vue', () => { const handleClear = vi.fn() const handleInput = vi.fn() const content = ref('a') + const handleTextareaClear = vi.fn() + const handleTextareaInput = vi.fn() + const textareaContent = ref('a') const wrapper = mount(() => ( - + <> + + + )) const input = wrapper.find('input') - const vm = wrapper.vm + const textarea = wrapper.find('textarea') // focus to show clear button await input.trigger('focus') await nextTick() - vm.$el.querySelector('.el-input__clear').click() + wrapper.find('.el-input__clear').trigger('click') await nextTick() expect(content.value).toEqual('') expect(handleClear).toBeCalled() expect(handleClear).toBeCalledWith(expect.any(MouseEvent)) expect(handleInput).toBeCalled() + // textarea + await textarea.trigger('focus') + await nextTick() + wrapper.find('.el-textarea__clear').trigger('click') + await nextTick() + expect(textareaContent.value).toEqual('') + expect(handleTextareaClear).toBeCalled() + expect(handleTextareaInput).toBeCalled() }) test('event:input', async () => { diff --git a/packages/components/input/src/input.vue b/packages/components/input/src/input.vue index 198f63cb4c..80d33ca370 100644 --- a/packages/components/input/src/input.vue +++ b/packages/components/input/src/input.vue @@ -121,7 +121,11 @@