From d79364946538d3381f0d093e08f47becf0867586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Jul 2024 03:34:05 +0800 Subject: [PATCH 1/2] chore: bump rc-input from 1.5.0 to 1.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba11dd2..9b678ee 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@babel/runtime": "^7.22.5", "@rc-component/trigger": "^2.0.0", "classnames": "^2.2.6", - "rc-input": "~1.5.0", + "rc-input": "~1.6.0", "rc-menu": "~9.14.0", "rc-textarea": "~1.7.0", "rc-util": "^5.34.1" From 59dd092223f26eb31fd8c5493fe36b743d331940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Jul 2024 14:41:27 +0800 Subject: [PATCH 2/2] feat: support onClear --- package.json | 2 +- src/Mentions.tsx | 4 +++- tests/AllowClear.spec.tsx | 29 ++++++++++++++--------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 9b678ee..239de6c 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "classnames": "^2.2.6", "rc-input": "~1.6.0", "rc-menu": "~9.14.0", - "rc-textarea": "~1.7.0", + "rc-textarea": "~1.8.0", "rc-util": "^5.34.1" }, "devDependencies": { diff --git a/src/Mentions.tsx b/src/Mentions.tsx index 61e3f8f..dbde5bc 100644 --- a/src/Mentions.tsx +++ b/src/Mentions.tsx @@ -23,11 +23,11 @@ import type { OptionProps } from './Option'; import Option from './Option'; import { filterOption as defaultFilterOption, + validateSearch as defaultValidateSearch, getBeforeSelectionText, getLastMeasureIndex, replaceWithMeasure, setInputSelection, - validateSearch as defaultValidateSearch, } from './util'; type BaseTextareaAttrs = Omit< @@ -514,6 +514,7 @@ const Mentions = forwardRef( classNames: classes, className, disabled, + onClear, ...rest }, ref, @@ -556,6 +557,7 @@ const Mentions = forwardRef( classNames={classes} disabled={disabled} ref={holderRef} + onClear={onClear} > { @@ -21,12 +21,7 @@ describe('should support allowClear', () => { it('should not show icon if value is undefined, null or empty string', () => { const wrappers = [null, undefined, ''].map(val => - render( - ['value']} - />, - ), + render(), ); wrappers.forEach(({ asFragment, container }) => { expect(container.querySelector('textarea')?.value).toEqual(''); @@ -39,14 +34,7 @@ describe('should support allowClear', () => { it('should not show icon if defaultValue is undefined, null or empty string', () => { const wrappers = [null, undefined, ''].map(val => - render( - ['value'] - } - />, - ), + render(), ); wrappers.forEach(({ asFragment, container }) => { expect(container.querySelector('textarea')?.value).toEqual(''); @@ -66,4 +54,15 @@ describe('should support allowClear', () => { expect(onChange).toHaveBeenCalledWith(''); expect(container.querySelector('textarea')?.value).toBe(''); }); + + it('should support onClear', () => { + const onClear = jest.fn(); + const { container } = render( + , + ); + fireEvent.click( + container.querySelector('.rc-mentions-clear-icon')!, + ); + expect(onClear).toHaveBeenCalled(); + }); });