Browse Source

fix(form): withField return component lossing ref when it without filed prop #384 (#386)

走鹃 3 years ago
parent
commit
c4e86123a7

+ 1 - 1
packages/semi-ui/form/hoc/withField.tsx

@@ -75,7 +75,7 @@ function withField<
         // 无需注入的直接返回,eg:Group内的checkbox、radio
         // Return without injection, eg: <Checkbox> / <Radio> inside CheckboxGroup/RadioGroup
         if (!shouldInject) {
-            return <Component {...rest} />;
+            return <Component {...rest} ref={ref} />;
         }
 
         // grab formState from context

+ 12 - 1
packages/semi-ui/radio/_story/radio.stories.js

@@ -2,7 +2,7 @@ import React, { useState } from 'react';
 import Button from '../../button';
 import Space from '../../space';
 
-import { Radio, RadioGroup } from '../../index';
+import { Radio, RadioGroup, Form, Tooltip } from '../../index';
 import { Row, Col } from '../../grid';
 import './radio.scss';
 
@@ -855,3 +855,14 @@ export const RadioGroupPureCardStyle = () => (
 RadioGroupPureCardStyle.story = {
   name: 'radioGroup pureCard style'
 }
+
+export const FixWithFieldLossRef = () => {
+  return (
+    <Form>
+        <Tooltip visible trigger="custom" content={'hi bytedance'}>
+            <Form.Radio>Semi</Form.Radio>
+        </Tooltip>
+    </Form>
+  );
+}
+FixWithFieldLossRef.storyName = '修复 Form Field 丢失 ref 问题 #384';