Coder Social home page Coder Social logo

Comments (5)

stackblitz avatar stackblitz commented on June 8, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from ant-design.

Wxh16144 avatar Wxh16144 commented on June 8, 2024

示例中的代码需要调整一下,antd 内置组件获取逻辑是优先判断转发的 ref

source code:

function getFieldDOMNode(name: NamePath, wrapForm: FormInstance) {
const field = wrapForm.getFieldInstance(name);
if (field instanceof HTMLElement) {
return field;
}
if (field?.nativeElement instanceof HTMLElement) {
return field.nativeElement;
}
const fieldId = getFieldId(toArray(name), wrapForm.__INTERNAL__.name);
if (fieldId) {
return document.getElementById(fieldId);
}
}

调整示例

-const ItemChildrenWrapper = (props: any) => {
+const ItemChildrenWrapper = React.forwardRef((props: any, ref) => {
   const { children, ...rest } = props
-  return React.cloneElement(children, rest)
-}
+  return React.cloneElement(children, { ...rest, ref })
+})

from ant-design.

crazyair avatar crazyair commented on June 8, 2024

嗯,也找了 id,但是 display none 了

from ant-design.

crazyair avatar crazyair commented on June 8, 2024
 return React.cloneElement(children, { ...rest, ref })

不能这样改,Upload 本身的 ref 方法没了
image

from ant-design.

Wxh16144 avatar Wxh16144 commented on June 8, 2024

群里已经讨论过了,贴一下结论:

antd 的 Form.Item 会合并 children 的 ref, 具体可以看一眼 https://github.com/ant-design/ant-design/blob/8b8021083ee9b6b1db305b62ff007503f8106ccd/components/form/hooks/useItemRef.ts Form.Item 是如何获得 ref 的

from ant-design.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.