Skip to content

Commit

Permalink
feat: extend Sender onChange parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
defaultjacky committed Dec 16, 2024
1 parent f04a8dd commit 05a7d6b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions components/sender/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ describe('Sender Component', () => {
);

fireEvent.change(container.querySelector('textarea')!, { target: { value: 'bamboo' } });
expect(onChange).toHaveBeenCalledWith('bamboo');
expect(onChange).toHaveBeenCalledWith('bamboo', {});

fireEvent.click(container.querySelector('button')!);
expect(onChange).toHaveBeenCalledWith('');
expect(onChange).toHaveBeenCalledWith('', undefined);
});

describe('submitType', () => {
Expand Down
8 changes: 4 additions & 4 deletions components/sender/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface SenderProps extends Pick<TextareaProps, 'placeholder' | 'onKeyP
submitType?: SubmitType;
disabled?: boolean;
onSubmit?: (message: string) => void;
onChange?: (value: string) => void;
onChange?: (value: string, e?: React.FormEvent<HTMLElement>) => void;
onCancel?: VoidFunction;
onKeyDown?: React.KeyboardEventHandler<any>;
onPaste?: React.ClipboardEventHandler<HTMLElement>;
Expand Down Expand Up @@ -142,11 +142,11 @@ function Sender(props: SenderProps, ref: React.Ref<HTMLDivElement>) {
value,
});

const triggerValueChange = (nextValue: string) => {
const triggerValueChange = (nextValue: string, e?: React.FormEvent<HTMLElement>) => {
setInnerValue(nextValue);

if (onChange) {
onChange(nextValue);
onChange(nextValue, e);
}
};

Expand Down Expand Up @@ -298,7 +298,7 @@ function Sender(props: SenderProps, ref: React.Ref<HTMLDivElement>) {
autoSize={{ maxRows: 8 }}
value={innerValue}
onChange={(e) => {
triggerValueChange((e.target as HTMLTextAreaElement).value);
triggerValueChange((e.target as HTMLTextAreaElement).value, e);
triggerSpeech(true);
}}
onPressEnter={onInternalKeyPress}
Expand Down
2 changes: 1 addition & 1 deletion components/sender/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ coverDark: https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*cOfrS4fVkOMAAA
| submitType | 提交模式 | SubmitType | `enter` \| `shiftEnter` | - |
| value | 输入框值 | string | - | - |
| onSubmit | 点击发送按钮的回调 | (message: string) => void | - | - |
| onChange | 输入框值改变的回调 | (value: string) => void | - | - |
| onChange | 输入框值改变的回调 | (value: string, e?: React.FormEvent<`HTMLElement`>) => void | - | - |
| onCancel | 点击取消按钮的回调 | () => void | - | - |

```typescript | pure
Expand Down

0 comments on commit 05a7d6b

Please sign in to comment.