mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 12:39:49 +08:00
feat(Checkbox): add onBlur and onFocus in types (#50842)
Co-authored-by: afc163 <afc163@gmail.com>
This commit is contained in:
parent
b6edef3af8
commit
7a521ab908
@ -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;
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
@ -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
|
||||
|
||||
|
@ -42,6 +42,8 @@ demo:
|
||||
| disabled | 失效状态 | boolean | false | |
|
||||
| indeterminate | 设置 indeterminate 状态,只负责样式控制 | boolean | false | |
|
||||
| onChange | 变化时的回调函数 | (e: CheckboxChangeEvent) => void | - | |
|
||||
| onBlur | 失去焦点时的回调 | function() | - | |
|
||||
| onFocus | 获得焦点时的回调 | function() | - | |
|
||||
|
||||
#### Checkbox Group
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user