diff --git a/components/checkbox/Group.tsx b/components/checkbox/Group.tsx index 51cb030c3a..45bc5d24a8 100644 --- a/components/checkbox/Group.tsx +++ b/components/checkbox/Group.tsx @@ -41,16 +41,19 @@ export interface CheckboxGroupContext { export const GroupContext = React.createContext(null); -const CheckboxGroup: React.FC = ({ - defaultValue, - children, - options = [], - prefixCls: customizePrefixCls, - className, - style, - onChange, - ...restProps -}) => { +const InternalCheckboxGroup: React.ForwardRefRenderFunction = ( + { + defaultValue, + children, + options = [], + prefixCls: customizePrefixCls, + className, + style, + onChange, + ...restProps + }, + ref, +) => { const { getPrefixCls, direction } = React.useContext(ConfigContext); const [value, setValue] = React.useState( @@ -147,10 +150,12 @@ const CheckboxGroup: React.FC = ({ className, ); return ( -
+
{children}
); }; +const CheckboxGroup = React.forwardRef(InternalCheckboxGroup); + export default React.memo(CheckboxGroup); diff --git a/components/checkbox/__tests__/group.test.js b/components/checkbox/__tests__/group.test.js index 702da4c29b..6cf014fe3e 100644 --- a/components/checkbox/__tests__/group.test.js +++ b/components/checkbox/__tests__/group.test.js @@ -202,4 +202,15 @@ describe('CheckboxGroup', () => { wrapper.find('.ant-checkbox-input').at(1).simulate('change'); expect(onChange).not.toHaveBeenCalled(); }); + + it('should get div ref', () => { + mount( + { + expect(node.nodeName).toBe('DIV'); + }} + />, + ); + }); });