Merge branch 'feature' into merge-into-feature

This commit is contained in:
Tom Xu 2020-10-21 14:31:16 +08:00
commit 1f1956ccd9
7 changed files with 30 additions and 9 deletions

View File

@ -49,6 +49,9 @@ const FormSizeDemo = () => {
<div className="example">
<Input.Search allowClear />
</div>
<div className="example">
<Input.TextArea allowClear />
</div>
<div className="example">
<Select defaultValue="demo" options={[{ value: 'demo' }]} />
</div>

View File

@ -31,6 +31,7 @@ Previewable image.
{
visible?: boolean;
onVisibleChange?: (visible, prevVisible) => void;
getContainer?: string | HTMLElement | (() => HTMLElement);
}
```

View File

@ -32,6 +32,7 @@ cover: https://gw.alipayobjects.com/zos/antfincdn/D1dXz9PZqa/image.svg
{
visible?: boolean;
onVisibleChange?: (visible, prevVisible) => void;
getContainer: string | HTMLElement | (() => HTMLElement);
}
```

View File

@ -5,12 +5,14 @@ import classNames from 'classnames';
import ClearableLabeledInput from './ClearableLabeledInput';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import { fixControlledValue, resolveOnChange } from './Input';
import SizeContext, { SizeType } from '../config-provider/SizeContext';
export interface TextAreaProps extends RcTextAreaProps {
allowClear?: boolean;
bordered?: boolean;
showCount?: boolean;
maxLength?: number;
size?: SizeType;
}
export interface TextAreaState {
@ -76,15 +78,17 @@ class TextArea extends React.Component<TextAreaProps, TextAreaState> {
resolveOnChange(this.resizableTextArea.textArea, e, this.props.onChange);
};
renderTextArea = (prefixCls: string, bordered: boolean) => {
const { showCount, className, style } = this.props;
renderTextArea = (prefixCls: string, bordered: boolean, size?: SizeType) => {
const { showCount, className, style, size: customizeSize } = this.props;
return (
<RcTextArea
{...omit(this.props, ['allowClear', 'bordered', 'showCount'])}
{...omit(this.props, ['allowClear', 'bordered', 'showCount', 'size'])}
className={classNames({
[`${prefixCls}-borderless`]: !bordered,
[className!]: className && !showCount,
[`${prefixCls}-sm`]: size === 'small' || customizeSize === 'small',
[`${prefixCls}-lg`]: size === 'large' || customizeSize === 'large',
})}
style={showCount ? null : style}
prefixCls={prefixCls}
@ -112,14 +116,14 @@ class TextArea extends React.Component<TextAreaProps, TextAreaState> {
value = hasMaxLength ? value.slice(0, maxLength) : value;
// TextArea
let textareaNode = (
let textareaNode = (size?: SizeType) => (
<ClearableLabeledInput
{...this.props}
prefixCls={prefixCls}
direction={direction}
inputType="text"
value={value}
element={this.renderTextArea(prefixCls, bordered)}
element={this.renderTextArea(prefixCls, bordered, size)}
handleReset={this.handleReset}
ref={this.saveClearableInput}
triggerFocus={this.focus}
@ -132,7 +136,7 @@ class TextArea extends React.Component<TextAreaProps, TextAreaState> {
const valueLength = [...value].length;
const dataCount = `${valueLength}${hasMaxLength ? ` / ${maxLength}` : ''}`;
textareaNode = (
textareaNode = (size?: SizeType) => (
<div
className={classNames(
`${prefixCls}-textarea`,
@ -145,12 +149,12 @@ class TextArea extends React.Component<TextAreaProps, TextAreaState> {
style={style}
data-count={dataCount}
>
{textareaNode}
{textareaNode(size)}
</div>
);
}
return textareaNode;
return <SizeContext.Consumer>{textareaNode}</SizeContext.Consumer>;
};
render() {

View File

@ -263,3 +263,9 @@ exports[`TextArea should support maxLength 1`] = `
maxlength="10"
/>
`;
exports[`TextArea should support size 1`] = `
<textarea
class="ant-input ant-input-lg"
/>
`;

View File

@ -155,6 +155,12 @@ describe('TextArea', () => {
expect(wrapper.find('.ant-input').props().style.background).toBeFalsy();
});
});
it('should support size', async () => {
const wrapper = mount(<TextArea size="large" />);
expect(wrapper.find('textarea').hasClass('ant-input-lg')).toBe(true);
expect(wrapper.render()).toMatchSnapshot();
});
});
describe('TextArea allowClear', () => {

View File

@ -125,7 +125,7 @@
"rc-drawer": "~4.1.0",
"rc-dropdown": "~3.2.0",
"rc-field-form": "~1.12.0",
"rc-image": "~3.2.1",
"rc-image": "~4.0.0",
"rc-input-number": "~6.1.0",
"rc-mentions": "~1.5.0",
"rc-menu": "~8.8.2",