Skip to content

Commit

Permalink
fix: rm onPressEnter (#62)
Browse files Browse the repository at this point in the history
* fix: rm onPressEnter

* fix: fix

* fix: fix
  • Loading branch information
li-jia-nan authored Jul 18, 2024
1 parent 7b5c922 commit 0c31fe5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
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();
});

0 comments on commit 0c31fe5

Please sign in to comment.