Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ResizableTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
// =============================== Render ===============================
const mergedAutoSizeStyle = needAutoSize ? autoSizeStyle : null;

const mergedStyle = {
const mergedStyle: React.CSSProperties = {
...style,
...mergedAutoSizeStyle,
};
Expand Down
7 changes: 5 additions & 2 deletions src/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
styles,
onResize,
onClear,
onPressEnter,
readOnly,
autoSize,
onKeyDown,
...rest
},
ref,
Expand Down Expand Up @@ -151,7 +154,6 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
};

const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
const { onPressEnter, onKeyDown } = rest;
if (e.key === 'Enter' && onPressEnter) {
onPressEnter(e);
}
Expand Down Expand Up @@ -208,7 +210,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
}
};

const isPureTextArea = !rest.autoSize && !showCount && !allowClear;
const isPureTextArea = !autoSize && !showCount && !allowClear;

return (
<BaseInput
Expand Down Expand Up @@ -243,6 +245,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
>
<ResizableTextArea
{...rest}
autoSize={autoSize}
maxLength={maxLength}
onKeyDown={handleKeyDown}
onChange={onInternalChange}
Expand Down
23 changes: 23 additions & 0 deletions tests/ResizableTextArea.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { render } from '@testing-library/react';
import React from 'react';
import type { ResizableTextAreaRef, TextAreaProps } from '../src';
import { ResizableTextArea } from '../src';

const resizableTextAreaProps = () => (global as any).textAreaProps;

jest.mock('../src/ResizableTextArea', () => {
const ReactReal: typeof React = jest.requireActual('react');
const Resizable = jest.requireActual('../src/ResizableTextArea');
const ResizableComponent = Resizable.default;
return ReactReal.forwardRef<ResizableTextAreaRef, TextAreaProps>(
(props, ref) => {
(global as any).textAreaProps = props;
return <ResizableComponent {...props} ref={ref} />;
},
);
});

it('should have no onPressEnter prop', () => {
render(<ResizableTextArea defaultValue="test" />);
expect(resizableTextAreaProps().onPressEnter).toBeUndefined();
});