From 6af1d95cf477e5bbdfc985091035f953d09c36ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Tue, 10 Oct 2023 16:22:23 +0800 Subject: [PATCH 01/96] feat: Input & TextArea support count (#45140) * docs: init * chore: update example * test: update test * docs: update doc * chore: fix lint * chore: update limit --- components/input/TextArea.tsx | 11 +- .../__snapshots__/demo-extend.test.ts.snap | 165 ++++++++++++------ .../__snapshots__/demo.test.tsx.snap | 161 +++++++++++------ components/input/__tests__/index.test.tsx | 31 ++-- components/input/__tests__/textarea.test.tsx | 108 +----------- components/input/demo/advance-count.md | 7 + components/input/demo/advance-count.tsx | 44 +++++ components/input/demo/show-count.tsx | 17 +- components/input/demo/textarea-show-count.md | 7 - components/input/demo/textarea-show-count.tsx | 29 --- components/input/index.en-US.md | 30 ++-- components/input/index.zh-CN.md | 28 ++- components/input/style/index.ts | 16 ++ package.json | 9 +- 14 files changed, 367 insertions(+), 296 deletions(-) create mode 100644 components/input/demo/advance-count.md create mode 100644 components/input/demo/advance-count.tsx delete mode 100644 components/input/demo/textarea-show-count.md delete mode 100644 components/input/demo/textarea-show-count.tsx diff --git a/components/input/TextArea.tsx b/components/input/TextArea.tsx index 21a44e6dbd7a..fc492694f992 100644 --- a/components/input/TextArea.tsx +++ b/components/input/TextArea.tsx @@ -1,17 +1,18 @@ +import * as React from 'react'; +import { forwardRef } from 'react'; import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled'; import classNames from 'classnames'; import type { BaseInputProps } from 'rc-input/lib/interface'; import type { TextAreaRef as RcTextAreaRef } from 'rc-textarea'; import RcTextArea from 'rc-textarea'; import type { TextAreaProps as RcTextAreaProps } from 'rc-textarea/lib/interface'; -import * as React from 'react'; -import { forwardRef } from 'react'; + import type { InputStatus } from '../_util/statusUtils'; import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils'; import { ConfigContext } from '../config-provider'; import DisabledContext from '../config-provider/DisabledContext'; -import type { SizeType } from '../config-provider/SizeContext'; import useSize from '../config-provider/hooks/useSize'; +import type { SizeType } from '../config-provider/SizeContext'; import { FormItemInputContext } from '../form/context'; import type { InputFocusOptions } from './Input'; import { triggerFocus } from './Input'; @@ -38,7 +39,6 @@ const TextArea = forwardRef((props, ref) => { disabled: customDisabled, status: customStatus, allowClear, - showCount, classNames: classes, rootClassName, className, @@ -99,7 +99,7 @@ const TextArea = forwardRef((props, ref) => { [`${prefixCls}-affix-wrapper-borderless`]: !bordered, [`${prefixCls}-affix-wrapper-sm`]: mergedSize === 'small', [`${prefixCls}-affix-wrapper-lg`]: mergedSize === 'large', - [`${prefixCls}-textarea-show-count`]: showCount, + [`${prefixCls}-textarea-show-count`]: props.showCount || props.count?.show, }, getStatusClassNames(`${prefixCls}-affix-wrapper`, mergedStatus), hashId, @@ -120,7 +120,6 @@ const TextArea = forwardRef((props, ref) => { }} prefixCls={prefixCls} suffix={hasFeedback && {feedbackIcon}} - showCount={showCount} ref={innerRef} />, ); diff --git a/components/input/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/input/__tests__/__snapshots__/demo-extend.test.ts.snap index b379db342c08..cc7a19e956e8 100644 --- a/components/input/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/input/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -602,6 +602,91 @@ exports[`renders components/input/demo/addon.tsx extend context correctly 1`] = exports[`renders components/input/demo/addon.tsx extend context correctly 2`] = `[]`; +exports[`renders components/input/demo/advance-count.tsx extend context correctly 1`] = ` +
+
+
+ Exceed Max +
+ + + + + 12 / 10 + + + +
+
+
+ Emoji count as length 1 +
+ + + + + 3 + + + +
+
+
+ Not exceed max +
+ + + + + 6 / 6 + + + +
+
+`; + +exports[`renders components/input/demo/advance-count.tsx extend context correctly 2`] = `[]`; + exports[`renders components/input/demo/align.tsx extend context correctly 1`] = ` Array [
@@ -10366,15 +10454,14 @@ Array [ 0 / 20 - , -
, -
, +