Skip to content

Commit 5acf691

Browse files
authored
feat: support onClear (#61)
* chore: bump rc-input from 1.5.0 to 1.6.0 * feat: support onClear
1 parent 5fe1ae3 commit 5acf691

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/ResizableTextArea.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
1616
(props, ref) => {
1717
const {
1818
prefixCls,
19-
onPressEnter,
2019
defaultValue,
2120
value,
2221
autoSize,

src/TextArea.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
3636
classNames,
3737
styles,
3838
onResize,
39+
onClear,
3940
readOnly,
4041
...rest
4142
},
@@ -238,6 +239,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
238239
}}
239240
hidden={hidden}
240241
readOnly={readOnly}
242+
onClear={onClear}
241243
>
242244
<ResizableTextArea
243245
{...rest}

src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type TextAreaProps = Omit<HTMLTextareaProps, 'onResize' | 'value'> & {
3636
count?: CSSProperties;
3737
};
3838
} & Pick<BaseInputProps, 'allowClear' | 'suffix'> &
39-
Pick<InputProps, 'showCount' | 'count'>;
39+
Pick<InputProps, 'showCount' | 'count' | 'onClear'>;
4040

4141
export type TextAreaRef = {
4242
resizableTextArea: ResizableTextAreaRef;

tests/allowClear.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,14 @@ it('should not textarea clear className', () => {
128128
container.querySelector('.rc-textarea-textarea-allow-clear'),
129129
).toBeFalsy();
130130
});
131+
132+
it('support onClear', () => {
133+
const onClear = jest.fn();
134+
const { container } = render(
135+
<TextArea onClear={onClear} defaultValue="test" allowClear />,
136+
);
137+
fireEvent.click(
138+
container.querySelector<HTMLSpanElement>('.rc-textarea-clear-icon')!,
139+
);
140+
expect(onClear).toHaveBeenCalled();
141+
});

0 commit comments

Comments
 (0)