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 @@