Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use rc-util getNodeRef #57

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"lint": "eslint src/ --ext .tsx,.ts",
"now-build": "npm run docs:build",
"prepare": "husky install",
"prepublishOnly": "npm run compile && np --yolo --no-publish",
"prepublishOnly": "npm run compile",
zombieJ marked this conversation as resolved.
Show resolved Hide resolved
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
"postpublish": "npm run docs:build && npm run docs:deploy",
"start": "dumi dev",
Expand All @@ -48,7 +48,7 @@
"dependencies": {
"@babel/runtime": "^7.11.1",
"classnames": "^2.2.1",
"rc-util": "^5.43.0"
"rc-util": "^5.44.0"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.1",
Expand Down
13 changes: 8 additions & 5 deletions src/CSSMotion.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/default-props-match-prop-types, react/no-multi-comp, react/prop-types */
import classNames from 'classnames';
import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
import { fillRef, supportRef } from 'rc-util/lib/ref';
import { fillRef, getNodeRef, supportRef } from 'rc-util/lib/ref';
import * as React from 'react';
import { useRef } from 'react';
import { Context } from './context';
Expand Down Expand Up @@ -233,12 +233,15 @@ export function genCSSMotion(config: CSSMotionConfig) {

// Auto inject ref if child node not have `ref` props
if (React.isValidElement(motionChildren) && supportRef(motionChildren)) {
const { ref: originNodeRef } = motionChildren as any;
const originNodeRef = getNodeRef(motionChildren);

if (!originNodeRef) {
motionChildren = React.cloneElement<any>(motionChildren, {
ref: setNodeRef,
});
motionChildren = React.cloneElement(
motionChildren as React.ReactElement,
{
ref: setNodeRef,
},
);
}
}

Expand Down
Loading