From 311a6c091774e69f057ebeee47a35db8a2343775 Mon Sep 17 00:00:00 2001 From: Liming Jin Date: Fri, 11 Oct 2019 18:12:28 +0800 Subject: [PATCH] fix: replace autosize with autoSize --- components/input/TextArea.tsx | 21 +++++++++++++------ .../__tests__/__snapshots__/demo.test.js.snap | 2 +- components/input/__tests__/index.test.js | 2 +- components/input/demo/autosize-textarea.md | 10 ++++----- components/input/demo/textarea-resize.md | 4 ++-- components/input/index.en-US.md | 2 +- components/input/index.zh-CN.md | 2 +- components/typography/Editable.tsx | 2 +- 8 files changed, 27 insertions(+), 18 deletions(-) diff --git a/components/input/TextArea.tsx b/components/input/TextArea.tsx index 830830e0fd11..23fe3d5f7cd1 100644 --- a/components/input/TextArea.tsx +++ b/components/input/TextArea.tsx @@ -6,6 +6,7 @@ import ResizeObserver from 'rc-resize-observer'; import calculateNodeHeight from './calculateNodeHeight'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import raf from '../_util/raf'; +import warning from '../_util/warning'; export interface AutoSizeType { minRows?: number; @@ -16,7 +17,9 @@ export type HTMLTextareaProps = React.TextareaHTMLAttributes; } @@ -84,11 +87,11 @@ class TextArea extends React.Component { }; resizeTextarea = () => { - const { autosize } = this.props; - if (!autosize || !this.textAreaRef) { + const autoSize = this.props.autoSize || this.props.autosize; + if (!autoSize || !this.textAreaRef) { return; } - const { minRows, maxRows } = autosize as AutoSizeType; + const { minRows, maxRows } = autoSize as AutoSizeType; const textareaStyles = calculateNodeHeight(this.textAreaRef, false, minRows, maxRows); this.setState({ textareaStyles, resizing: true }, () => { raf.cancel(this.resizeFrameId); @@ -108,14 +111,20 @@ class TextArea extends React.Component { renderTextArea = ({ getPrefixCls }: ConfigConsumerProps) => { const { textareaStyles, resizing } = this.state; - const { prefixCls: customizePrefixCls, className, disabled, autosize } = this.props; + const { prefixCls: customizePrefixCls, className, disabled, autoSize, autosize } = this.props; const { ...props } = this.props; - const otherProps = omit(props, ['prefixCls', 'onPressEnter', 'autosize']); + const otherProps = omit(props, ['prefixCls', 'onPressEnter', 'autoSize', 'autosize']); const prefixCls = getPrefixCls('input', customizePrefixCls); const cls = classNames(prefixCls, className, { [`${prefixCls}-disabled`]: disabled, }); + warning( + autosize === undefined, + 'Input.TextArea', + 'autosize is deprecated, please use autoSize instead.', + ); + const style = { ...props.style, ...textareaStyles, @@ -127,7 +136,7 @@ class TextArea extends React.Component { otherProps.value = otherProps.value || ''; } return ( - + `; diff --git a/components/input/__tests__/index.test.js b/components/input/__tests__/index.test.js index 8af8c199f7e9..581737b5f3ec 100644 --- a/components/input/__tests__/index.test.js +++ b/components/input/__tests__/index.test.js @@ -74,7 +74,7 @@ describe('TextArea', () => { }); it('should auto calculate height according to content length', () => { - const wrapper = mount(