feat(Checkbox): add onBlur and onFocus in types (#50842)

Co-authored-by: afc163 <afc163@gmail.com>
This commit is contained in:
huiliangShen 2024-09-14 14:39:53 +08:00 committed by GitHub
parent b6edef3af8
commit 7a521ab908
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,8 @@ export interface AbstractCheckboxProps<T> {
onMouseLeave?: React.MouseEventHandler<HTMLElement>;
onKeyPress?: React.KeyboardEventHandler<HTMLElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLElement>;
onFocus?: React.FocusEventHandler<HTMLElement>;
onBlur?: React.FocusEventHandler<HTMLElement>;
value?: any;
tabIndex?: number;
name?: string;

View File

@ -37,4 +37,19 @@ describe('Checkbox', () => {
);
errorSpy.mockRestore();
});
// https://github.com/ant-design/ant-design/issues/50768
it('onFocus / onBlur', () => {
const onBlur = jest.fn();
const onFocus = jest.fn();
const { container } = render(<Checkbox onBlur={onBlur} onFocus={onFocus} />);
const inputEl = container.querySelector('input')!;
fireEvent.focus(inputEl);
fireEvent.blur(inputEl);
expect(onFocus).toHaveBeenCalledTimes(1);
expect(onBlur).toHaveBeenCalledTimes(1);
});
});

View File

@ -41,6 +41,8 @@ Common props ref[Common props](/docs/react/common-props)
| disabled | If disable checkbox | boolean | false | |
| indeterminate | The indeterminate checked state of checkbox | boolean | false | |
| onChange | The callback function that is triggered when the state changes | (e: CheckboxChangeEvent) => void | - | |
| onBlur | Called when leaving the component | function() | - | |
| onFocus | Called when entering the component | function() | - | |
#### Checkbox Group

View File

@ -42,6 +42,8 @@ demo:
| disabled | 失效状态 | boolean | false | |
| indeterminate | 设置 indeterminate 状态,只负责样式控制 | boolean | false | |
| onChange | 变化时的回调函数 | (e: CheckboxChangeEvent) => void | - | |
| onBlur | 失去焦点时的回调 | function() | - | |
| onFocus | 获得焦点时的回调 | function() | - | |
#### Checkbox Group