Skip to content

Commit 0c31fe5

Browse files
authored
fix: rm onPressEnter (#62)
* fix: rm onPressEnter * fix: fix * fix: fix
1 parent 7b5c922 commit 0c31fe5

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/ResizableTextArea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
160160
// =============================== Render ===============================
161161
const mergedAutoSizeStyle = needAutoSize ? autoSizeStyle : null;
162162

163-
const mergedStyle = {
163+
const mergedStyle: React.CSSProperties = {
164164
...style,
165165
...mergedAutoSizeStyle,
166166
};

src/TextArea.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
3737
styles,
3838
onResize,
3939
onClear,
40+
onPressEnter,
4041
readOnly,
42+
autoSize,
43+
onKeyDown,
4144
...rest
4245
},
4346
ref,
@@ -151,7 +154,6 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
151154
};
152155

153156
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
154-
const { onPressEnter, onKeyDown } = rest;
155157
if (e.key === 'Enter' && onPressEnter) {
156158
onPressEnter(e);
157159
}
@@ -208,7 +210,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
208210
}
209211
};
210212

211-
const isPureTextArea = !rest.autoSize && !showCount && !allowClear;
213+
const isPureTextArea = !autoSize && !showCount && !allowClear;
212214

213215
return (
214216
<BaseInput
@@ -243,6 +245,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
243245
>
244246
<ResizableTextArea
245247
{...rest}
248+
autoSize={autoSize}
246249
maxLength={maxLength}
247250
onKeyDown={handleKeyDown}
248251
onChange={onInternalChange}

tests/ResizableTextArea.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { render } from '@testing-library/react';
2+
import React from 'react';
3+
import type { ResizableTextAreaRef, TextAreaProps } from '../src';
4+
import { ResizableTextArea } from '../src';
5+
6+
const resizableTextAreaProps = () => (global as any).textAreaProps;
7+
8+
jest.mock('../src/ResizableTextArea', () => {
9+
const ReactReal: typeof React = jest.requireActual('react');
10+
const Resizable = jest.requireActual('../src/ResizableTextArea');
11+
const ResizableComponent = Resizable.default;
12+
return ReactReal.forwardRef<ResizableTextAreaRef, TextAreaProps>(
13+
(props, ref) => {
14+
(global as any).textAreaProps = props;
15+
return <ResizableComponent {...props} ref={ref} />;
16+
},
17+
);
18+
});
19+
20+
it('should have no onPressEnter prop', () => {
21+
render(<ResizableTextArea defaultValue="test" />);
22+
expect(resizableTextAreaProps().onPressEnter).toBeUndefined();
23+
});

0 commit comments

Comments
 (0)