Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extend Sender onChange parameter #362

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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', {});
defaultjacky marked this conversation as resolved.
Show resolved Hide resolved
YumoImer marked this conversation as resolved.
Show resolved Hide resolved

fireEvent.click(container.querySelector('button')!);
expect(onChange).toHaveBeenCalledWith('');
expect(onChange).toHaveBeenCalledWith('', undefined);
YumoImer marked this conversation as resolved.
Show resolved Hide resolved
});

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;
YumoImer marked this conversation as resolved.
Show resolved Hide resolved
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);
defaultjacky marked this conversation as resolved.
Show resolved Hide resolved
}
};

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 | - | - |
YumoImer marked this conversation as resolved.
Show resolved Hide resolved
| onCancel | 点击取消按钮的回调 | () => void | - | - |

```typescript | pure
Expand Down
Loading