diff --git a/src/index.tsx b/src/index.tsx index e751ad9..aac4eee 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,6 +18,7 @@ export interface CheckboxRef { focus: (options?: FocusOptions) => void; blur: () => void; input: HTMLInputElement | null; + nativeElement: HTMLElement | null; } export interface CheckboxProps @@ -41,6 +42,8 @@ export const Checkbox = forwardRef((props, ref) => { } = props; const inputRef = useRef(null); + const holderRef = useRef(null); + const [rawValue, setRawValue] = useMergedState(defaultChecked, { value: checked, }); @@ -53,6 +56,7 @@ export const Checkbox = forwardRef((props, ref) => { inputRef.current?.blur(); }, input: inputRef.current, + nativeElement: holderRef.current, })); const classString = classNames(prefixCls, className, { @@ -86,7 +90,7 @@ export const Checkbox = forwardRef((props, ref) => { }; return ( - + { expect(ref.current?.input).toBe(inputEl); }); + + it('nativeElement should work', () => { + const ref = React.createRef(); + + const { container } = render(); + const holderEl = container.querySelector('.rc-checkbox')!; + + expect(ref.current?.nativeElement).toBe(holderEl); + }); });