Skip to content

Commit

Permalink
Merge branch 'main' into docs/fix-spec-introduce
Browse files Browse the repository at this point in the history
  • Loading branch information
YumoImer authored Dec 20, 2024
2 parents 728f93f + 49b6c89 commit 7b74762
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 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
2 changes: 1 addition & 1 deletion components/sender/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Common props ref:[Common props](/docs/react/common-props)
| submitType | Submit type | SubmitType | `enter` \| `shiftEnter` | - |
| value | Input value | string | - | - |
| onSubmit | Callback when click send button | (message: string) => void | - | - |
| onChange | Callback when input value changes | (value: string) => void | - | - |
| onChange | Callback when input value changes | (value: string, event?: React.FormEvent<`HTMLTextAreaElement`> \| React.ChangeEvent<`HTMLTextAreaElement`> ) => void | - | - |
| onCancel | Callback when click cancel button | () => void | - | - |

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

const triggerValueChange = (nextValue: string) => {
const triggerValueChange: SenderProps['onChange'] = (nextValue, event) => {
setInnerValue(nextValue);

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

Expand Down Expand Up @@ -297,8 +300,11 @@ function Sender(props: SenderProps, ref: React.Ref<HTMLDivElement>) {
className={classnames(inputCls, contextConfig.classNames.input, classNames.input)}
autoSize={{ maxRows: 8 }}
value={innerValue}
onChange={(e) => {
triggerValueChange((e.target as HTMLTextAreaElement).value);
onChange={(event) => {
triggerValueChange(
(event.target as HTMLTextAreaElement).value,
event as React.ChangeEvent<HTMLTextAreaElement>,
);
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, event?: React.FormEvent<`HTMLTextAreaElement`> \| React.ChangeEvent<`HTMLTextAreaElement`> ) => void | - | - |
| onCancel | 点击取消按钮的回调 | () => void | - | - |

```typescript | pure
Expand Down

0 comments on commit 7b74762

Please sign in to comment.